Peter Otten <__pete...@web.de> writes:
> >>> pattern = re.compile("(\d+)$")
> >>> match = pattern.search( "LINE: 235 : Primary Shelf Number (attempt 1): 1")
> >>> match.group()
> '1'
An alternative way to accomplish the above using the ‘match’ method::
>>> import re
>>> pattern = re.comp
James Smith wrote:
> I want the last "1"
> I can't this to work:
>
pattern=re.compile( "(\d+)$" )
match=pattern.match( "LINE: 235 : Primary Shelf Number (attempt 1): 1")
print match.group()
>>> pattern = re.compile("(\d+)$")
>>> match = pattern.search( "LINE: 235 : Primary Shelf N
I want the last "1"
I can't this to work:
>>> pattern=re.compile( "(\d+)$" )
>>> match=pattern.match( "LINE: 235 : Primary Shelf Number (attempt 1): 1")
>>> print match.group()
--
https://mail.python.org/mailman/listinfo/python-list
On Tue, 12 Apr 2011 22:11:55 +0300
Yuri Slobodyanyuk wrote:
> Thanks for the insight, while this code will run once a week and
> optimization isn't really a must here, it is
> still a good idea not to leave half-baked code behind me, especially given
> that it will be running on this server for
Thanks for the insight, while this code will run once a week and
optimization isn't really a must here, it is
still a good idea not to leave half-baked code behind me, especially given
that it will be running on this server for the next 13 years ;)
I have one doubt though . Doesn't using the lis
On Tue, 12 Apr 2011 15:06:25 +0300
Yuri Slobodyanyuk wrote:
> Thanks everybody , and especially Chris - i used split and it took me 15
> mins to make it work :)
That's great. One thing though...
> for nnn in hhh:
> if nnn.split()[2] == str(time_tuple[1]).strip(' \t\n\r') and
> nnn.split()
Thanks everybody , and especially Chris - i used split and it took me 15
mins to make it work :)
The final version looks like:
from datetime import datetime, date, time
today_day = datetime.now()
time_tuple= today_day.timetuple()
hhh = open("file_with_data.data",'r')
for nnn in hhh:
if nnn.sp
On Mon, Apr 11, 2011 at 10:20 PM, Yuri Slobodyanyuk
wrote:
> Good day everyone,
> I am trying to make this pretty simple regex to work but got stuck,
> I'd appreciate your help .
"Some people, when confronted with a problem, think 'I know, I'll use
regular expressions.' Now they have two problems
On Mon, Apr 11, 2011 at 10:20 PM, Yuri Slobodyanyuk
wrote:
> Good day everyone,
> I am trying to make this pretty simple regex to work but got stuck,
> I'd appreciate your help .
> Task: Get current date , then read file of format below, find the line that
> matches
> the current date of month,mon
On Tue, Apr 12, 2011 at 10:50 AM, Yuri Slobodyanyuk
wrote:
> Good day everyone,
> I am trying to make this pretty simple regex to work but got stuck,
> I'd appreciate your help .
> Task: Get current date , then read file of format below, find the line that
> matches
> the current date of month,mon
Good day everyone,
I am trying to make this pretty simple regex to work but got stuck,
I'd appreciate your help .
Task: Get current date , then read file of format below, find the line that
matches
the current date of month,month and year and extract the number from such
line.
Here is what I did ,
Thanks,
works great.
matt
On 3/3/2011 10:53 AM, MRAB wrote:
> On 03/03/2011 17:33, maf...@nmsu.edu wrote:
>> Hi,
>>
>> i have a line that looks something like:
>> 2.234e+04 3.456e+02 7.234e+07 1.543e+04: some description
>>
>> I would like to extract all the numbers. From the python website i
>>
On 03/03/2011 17:33, maf...@nmsu.edu wrote:
Hi,
i have a line that looks something like:
2.234e+04 3.456e+02 7.234e+07 1.543e+04: some description
I would like to extract all the numbers. From the python website i got the
following expression for matching what in c is %e (i.e. scientific
format
Hi,
i have a line that looks something like:
2.234e+04 3.456e+02 7.234e+07 1.543e+04: some description
I would like to extract all the numbers. From the python website i got the
following expression for matching what in c is %e (i.e. scientific
format):
(see http://docs.python.org/library/re.html
Schif Schaf wrote:
On Feb 7, 8:57 am, Tim Chase wrote:
Steve Holden wrote:
Really? Under what circumstances does a simple one-for-one character
replacement operation fail?
Failure is only defined in the clarified context of what the OP
wants :) Replacement operations only fai
On Feb 7, 8:57 am, Tim Chase wrote:
> Steve Holden wrote:
>
> > Really? Under what circumstances does a simple one-for-one character
> > replacement operation fail?
>
> Failure is only defined in the clarified context of what the OP
> wants :) Replacement operations only fail if the OP's desired
Steve Holden wrote:
Tim Chase wrote:
And to answer those who are reaching for other non-regex (whether string
translations or .replace(), or pyparsing) solutions, it depends on what
you want to happen in pathological cases like
s = """Dangling closing]
with properly [[nested]] and
c
Tim Chase wrote:
> Schif Schaf wrote:
>> On Feb 7, 12:19 am, "Alf P. Steinbach" wrote:
>>> I haven't used regexps in Python before, but what I did was (1) look
>>> in the
>>> documentation,
> [snip]
>>>
>>> import re
>>>
>>> text = (
>>> "Lorem [ipsum] dolor sit amet, consectetur",
>>>
Schif Schaf writes:
> (brackets replaced by braces). I can do that with Perl pretty easily:
>
>
> for (<>) {
> s/\[(.+?)\]/\{$1\}/g;
> print;
> }
>
Just curious, but since this is just transpose, then why not simply
tr/[]/{}/? I.e. why use a regular expression at all for this?
@ Rocteur CC wrote:
>
> On 07 Feb 2010, at 10:03, Shashwat Anand wrote:
>
>> Here is one simple solution :
>> >>> intext = """Lorem [ipsum] dolor sit amet, consectetur adipisicing
>> elit, sed do eiusmod tempor incididunt ut [labore] et [dolore] magna
>> aliqua."""
>>
>> >>> intext.replace('[',
Schif Schaf wrote:
On Feb 7, 12:19 am, "Alf P. Steinbach" wrote:
I haven't used regexps in Python before, but what I did was (1) look in the
documentation,
[snip]
import re
text = (
"Lorem [ipsum] dolor sit amet, consectetur",
"adipisicing elit, sed do eiusmod tempor",
"incid
On 07 Feb 2010, at 10:03, Shashwat Anand wrote:
Here is one simple solution :
>>> intext = """Lorem [ipsum] dolor sit amet, consectetur
adipisicing elit, sed do eiusmod tempor incididunt ut [labore] et
[dolore] magna aliqua."""
>>> intext.replace('[', '{').replace(']', '}')
'Lorem {ipsum
Here is one simple solution :
>>> intext = """Lorem [ipsum] dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut [labore] et [dolore] magna aliqua."""
>>> intext.replace('[', '{').replace(']',
'}')
'Lorem {ipsum} dolor sit amet, consectetur adipisicing elit, sed do ei
On Feb 7, 12:19 am, "Alf P. Steinbach" wrote:
>
> I haven't used regexps in Python before, but what I did was (1) look in the
> documentation,
Hm. I checked in the repl, running `import re; help(re)` and the docs
on the `sub()` method didn't say anything about using back-refs in the
replacement
* Schif Schaf:
Hi,
I've got some text that looks like this:
Lorem [ipsum] dolor sit amet, consectetur
adipisicing elit, sed do eiusmod tempor
incididunt ut [labore] et [dolore] magna aliqua.
and I want to make it look like this:
Lorem {ipsum} dolor sit amet, consectetur
Hi,
I've got some text that looks like this:
Lorem [ipsum] dolor sit amet, consectetur
adipisicing elit, sed do eiusmod tempor
incididunt ut [labore] et [dolore] magna aliqua.
and I want to make it look like this:
Lorem {ipsum} dolor sit amet, consectetur
adipisicing elit,
On Wed, Oct 14, 2009 at 10:30 AM, Zero Piraeus wrote:
> '(?:etc)' instead of '(etc)' are non-grouping parentheses (since you
> apparently don't care about that bit).
Ah yes, thanks.
> '[^\]]' instead of '[\w\s]' matches "everything except a closing bracket".
I originally had just '[^\]', and I
:
2009/10/14 Timur Tabi :
> Never mind ... I figured it out. The middle block should have been [\w
> \s/]*
This is fragile - you'll have to keep adding extra characters to match
if the input turns out to contain them.
-[]z.
--
http://mail.python.org/mailman/listinfo/python-list
:
2009/10/14 Timur Tabi :
> I'm having trouble creating a regex pattern that matches a string that
> has an optional substring in it. What I'm looking for is a pattern
> that matches both of these strings:
>
> Subject: [PATCH 08/18] This is the patch name
> Subject: This is the patch name
>
> Wha
On Oct 14, 9:51 am, Timur Tabi wrote:
> I'm having trouble creating a regex pattern that matches a string that
> has an optional substring in it. What I'm looking for is a pattern
> that matches both of these strings:
>
> Subject: [PATCH 08/18] This is the patch name
> Subject: This is the patch
I'm having trouble creating a regex pattern that matches a string that
has an optional substring in it. What I'm looking for is a pattern
that matches both of these strings:
Subject: [PATCH 08/18] This is the patch name
Subject: This is the patch name
What I want is to extract the "This is the p
On Thu, 06 Aug 2009 17:02:44 +0100, MRAB wrote:
> The character class \d is equivalent to [0-9]
Not for Unicode, which is the default in 3.x.
--
http://mail.python.org/mailman/listinfo/python-list
On Thu, 06 Aug 2009 14:23:47 -0700, Ethan Furman wrote:
>> [0-9]+ allows any number of leading zeros, which is sometimes undesirable.
>> Using:
>>
>> (0|[1-9][0-9]*)
>>
>> is more robust.
>
> You make a good point about possibly being undesirable, but I question
> the assertion that your
On Aug 7, 7:23 am, Ethan Furman wrote:
> Nobody wrote:
> > On Thu, 06 Aug 2009 08:35:57 -0700, Robert Dailey wrote:
>
> >>I'm creating a python script that is going to try to search a text
> >>file for any text that matches my regular expression. The thing it is
> >>looking for is:
>
> >>FILEVERSI
Nobody wrote:
On Thu, 06 Aug 2009 08:35:57 -0700, Robert Dailey wrote:
I'm creating a python script that is going to try to search a text
file for any text that matches my regular expression. The thing it is
looking for is:
FILEVERSION #,#,#,#
The # symbol represents any number that can be a
On Thu, 06 Aug 2009 08:35:57 -0700, Robert Dailey wrote:
> I'm creating a python script that is going to try to search a text
> file for any text that matches my regular expression. The thing it is
> looking for is:
>
> FILEVERSION #,#,#,#
>
> The # symbol represents any number that can be any l
On Aug 6, 11:12 am, Roman wrote:
> On 06/08/09 08:35, Robert Dailey wrote:
>
>
>
>
>
> > Hey guys,
>
> > I'm creating a python script that is going to try to search a text
> > file for any text that matches my regular expression. The thing it is
> > looking for is:
>
> > FILEVERSION #,#,#,#
>
> >
On 06/08/09 08:35, Robert Dailey wrote:
> Hey guys,
>
> I'm creating a python script that is going to try to search a text
> file for any text that matches my regular expression. The thing it is
> looking for is:
>
> FILEVERSION #,#,#,#
>
> The # symbol represents any number that can be any leng
Robert Dailey wrote:
On Aug 6, 11:02 am, MRAB wrote:
Robert Dailey wrote:
Hey guys,
I'm creating a python script that is going to try to search a text
file for any text that matches my regular expression. The thing it is
looking for is:
FILEVERSION #,#,#,#
The # symbol represents any number th
On Aug 6, 11:02 am, MRAB wrote:
> Robert Dailey wrote:
> > Hey guys,
>
> > I'm creating a python script that is going to try to search a text
> > file for any text that matches my regular expression. The thing it is
> > looking for is:
>
> > FILEVERSION #,#,#,#
>
> > The # symbol represents any nu
On Aug 7, 1:35 am, Robert Dailey wrote:
> I'm creating a python script that is going to try to search a text
> file for any text that matches my regular expression. The thing it is
> looking for is:
>
> FILEVERSION 1,45,10082,3
Would it be easier to do it without regex? The following is untested
Robert Dailey wrote:
Hey guys,
I'm creating a python script that is going to try to search a text
file for any text that matches my regular expression. The thing it is
looking for is:
FILEVERSION #,#,#,#
The # symbol represents any number that can be any length 1 or
greater. Example:
FILEVERS
Hey guys,
I'm creating a python script that is going to try to search a text
file for any text that matches my regular expression. The thing it is
looking for is:
FILEVERSION #,#,#,#
The # symbol represents any number that can be any length 1 or
greater. Example:
FILEVERSION 1,45,10082,3
The r
In article ,
MRAB wrote:
>Nobody wrote:
>> On Thu, 30 Jul 2009 10:29:09 -0700, rurpy wrote:
>>
regex = re.compile(r'[\w\-\.]+\.(?:us|au|de)')
>>> You might also want to consider that some country
>>> codes such as "co" for Columbia might match more than
>>> you want, for example:
>>>
>>>
Nobody wrote:
On Thu, 30 Jul 2009 10:29:09 -0700, rurpy wrote:
regex = re.compile(r'[\w\-\.]+\.(?:us|au|de)')
You might also want to consider that some country
codes such as "co" for Columbia might match more than
you want, for example:
re.match(r'[\w\-\.]+\.(?:us|au|de|co)', 'foo.boo.com')
On Thu, 30 Jul 2009 10:29:09 -0700, rurpy wrote:
>> regex = re.compile(r'[\w\-\.]+\.(?:us|au|de)')
>
> You might also want to consider that some country
> codes such as "co" for Columbia might match more than
> you want, for example:
>
> re.match(r'[\w\-\.]+\.(?:us|au|de|co)', 'foo.boo.com')
>
On Jul 30, 9:56 am, MRAB wrote:
> Feyo wrote:
> > I'm trying to figure out how to write efficiently write a regex for
> > domain names with a particular top level domain. Let's say, I want to
> > grab all domain names with country codes .us, .au, and .de.
>
> > I could create three different regex
On Jul 30, 11:56 am, MRAB wrote:
> Feyo wrote:
> > I'm trying to figure out how to write efficiently write a regex for
> > domain names with a particular top level domain. Let's say, I want to
> > grab all domain names with country codes .us, .au, and .de.
>
> > I could create three different rege
Feyo wrote:
I'm trying to figure out how to write efficiently write a regex for
domain names with a particular top level domain. Let's say, I want to
grab all domain names with country codes .us, .au, and .de.
I could create three different regexs that would work:
regex = re.compile(r'[\w\-\.]+\
Feyo wrote:
> I'm trying to figure out how to write efficiently write a regex for
> domain names with a particular top level domain. Let's say, I want to
> grab all domain names with country codes .us, .au, and .de.
>
> I could create three different regexs that would work:
> regex = re.compile(r'
I'm trying to figure out how to write efficiently write a regex for
domain names with a particular top level domain. Let's say, I want to
grab all domain names with country codes .us, .au, and .de.
I could create three different regexs that would work:
regex = re.compile(r'[\w\-\.]+\.us)
regex = r
Catalina Scott A Contr AFCA/EVEO wrote:
> I have a file with lines in the following format.
>
> pie=apple,quantity=1,cooked=yes,ingredients='sugar and cinnamon'
> Pie=peach,quantity=2,ingredients='peaches,powdered sugar'
> Pie=cherry,quantity=3,cooked=no,price=5,ingredients='cherries and sugar'
>
Dennis Benzinger wrote:
> Christopher Subich schrieb:
>> Paul McGuire wrote:
>>
>> [...]
>> For the example listed, pyparsing is even overkill; the OP should
>> probably use the csv module.
>
> But the OP wants to parse lines with key=value pairs, not simply lines
> with comma separated values. U
Fredrik Lundh wrote:
> Scott wrote:
>
> > I have a file with lines in the following format.
> >
> > pie=apple,quantity=1,cooked=yes,ingredients='sugar and cinnamon'
> > Pie=peach,quantity=2,ingredients='peaches,powdered sugar'
> > Pie=cherry,quantity=3,cooked=no,price=5,ingredients='cherries and s
Christopher Subich schrieb:
> Paul McGuire wrote:
>
> [...]
> For the example listed, pyparsing is even overkill; the OP should
> probably use the csv module.
But the OP wants to parse lines with key=value pairs, not simply lines
with comma separated values. Using the csv module will just separa
Catalina Scott A Contr AFCA/EVEO schrieb:
> I have a file with lines in the following format.
>
> pie=apple,quantity=1,cooked=yes,ingredients='sugar and cinnamon'
> Pie=peach,quantity=2,ingredients='peaches,powdered sugar'
> Pie=cherry,quantity=3,cooked=no,price=5,ingredients='cherries and sugar'
Paul McGuire wrote:
> This isn't a regex solution, but uses pyparsing instead. Pyparsing
> helps you construct recursive-descent parsers, and maintains a code
> structure that is easy to compose, read, understand, maintain, and
> remember what you did 6-months after you wrote it in the first place
Scott wrote:
> I have a file with lines in the following format.
>
> pie=apple,quantity=1,cooked=yes,ingredients='sugar and cinnamon'
> Pie=peach,quantity=2,ingredients='peaches,powdered sugar'
> Pie=cherry,quantity=3,cooked=no,price=5,ingredients='cherries and sugar'
>
> I would like to pull out
This isn't a regex solution, but uses pyparsing instead. Pyparsing
helps you construct recursive-descent parsers, and maintains a code
structure that is easy to compose, read, understand, maintain, and
remember what you did 6-months after you wrote it in the first place.
Download pyparsing at htt
I have a file with lines in the following format.
pie=apple,quantity=1,cooked=yes,ingredients='sugar and cinnamon'
Pie=peach,quantity=2,ingredients='peaches,powdered sugar'
Pie=cherry,quantity=3,cooked=no,price=5,ingredients='cherries and sugar'
I would like to pull out some of the values and wri
60 matches
Mail list logo