Re: help with regex

2014-10-08 Thread Ben Finney
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

Re: help with regex

2014-10-07 Thread Peter Otten
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

help with regex

2014-10-07 Thread James Smith
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

Re: Help with regex needed

2011-04-12 Thread D'Arcy J.M. Cain
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

Re: Help with regex needed

2011-04-12 Thread Yuri Slobodyanyuk
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

Re: Help with regex needed

2011-04-12 Thread D'Arcy J.M. Cain
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()

Re: Help with regex needed

2011-04-12 Thread Yuri Slobodyanyuk
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

Re: Help with regex needed

2011-04-11 Thread Chris Rebert
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

Re: Help with regex needed

2011-04-11 Thread Chris Rebert
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

Re: Help with regex needed

2011-04-11 Thread Kushal Kumaran
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

Help with regex needed

2011-04-11 Thread Yuri Slobodyanyuk
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 ,

Re: help with regex matching multiple %e

2011-03-03 Thread Matt Funk
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 >>

Re: help with regex matching multiple %e

2011-03-03 Thread MRAB
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

help with regex matching multiple %e

2011-03-03 Thread mafunk
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

Re: Help with regex search-and-replace (Perl to Python)

2010-02-08 Thread Anthra Norell
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

Re: Help with regex search-and-replace (Perl to Python)

2010-02-07 Thread Schif Schaf
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

Re: Help with regex search-and-replace (Perl to Python)

2010-02-07 Thread Tim Chase
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

Re: Help with regex search-and-replace (Perl to Python)

2010-02-07 Thread Steve Holden
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", >>>

Re: Help with regex search-and-replace (Perl to Python)

2010-02-07 Thread Anssi Saari
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?

Re: Help with regex search-and-replace (Perl to Python)

2010-02-07 Thread Steve Holden
@ 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('[',

Re: Help with regex search-and-replace (Perl to Python)

2010-02-07 Thread Tim Chase
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

Re: Help with regex search-and-replace (Perl to Python)

2010-02-07 Thread @ Rocteur CC
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

Re: Help with regex search-and-replace (Perl to Python)

2010-02-07 Thread Shashwat Anand
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

Re: Help with regex search-and-replace (Perl to Python)

2010-02-06 Thread Schif Schaf
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

Re: Help with regex search-and-replace (Perl to Python)

2010-02-06 Thread Alf P. Steinbach
* 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

Help with regex search-and-replace (Perl to Python)

2010-02-06 Thread 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 adipisicing elit,

Re: Help with regex and optional substring in search string

2009-10-14 Thread Timur Tabi
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

Re: Help with regex and optional substring in search string

2009-10-14 Thread Zero Piraeus
: 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

Re: Help with regex and optional substring in search string

2009-10-14 Thread Zero Piraeus
: 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

Re: Help with regex and optional substring in search string

2009-10-14 Thread Timur Tabi
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

Help with regex and optional substring in search string

2009-10-14 Thread 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 What I want is to extract the "This is the p

Re: Help with regex

2009-08-08 Thread Nobody
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

Re: Help with regex

2009-08-06 Thread Nobody
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

Re: Help with regex

2009-08-06 Thread John Machin
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

Re: Help with regex

2009-08-06 Thread Ethan Furman
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

Re: Help with regex

2009-08-06 Thread Nobody
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

Re: Help with regex

2009-08-06 Thread Robert Dailey
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 #,#,#,# > > >

Re: Help with regex

2009-08-06 Thread Roman
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

Re: Help with regex

2009-08-06 Thread MRAB
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

Re: Help with regex

2009-08-06 Thread Robert Dailey
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

Re: Help with regex

2009-08-06 Thread alex23
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

Re: Help with regex

2009-08-06 Thread MRAB
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

Help with regex

2009-08-06 Thread Robert Dailey
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

Re: Help with Regex for domain names

2009-08-02 Thread Aahz
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: >>> >>>

Re: Help with Regex for domain names

2009-07-30 Thread MRAB
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')

Re: Help with Regex for domain names

2009-07-30 Thread Nobody
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') >

Re: Help with Regex for domain names

2009-07-30 Thread rurpy
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

Re: Help with Regex for domain names

2009-07-30 Thread Feyo
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

Re: Help with Regex for domain names

2009-07-30 Thread MRAB
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\-\.]+\

Re: Help with Regex for domain names

2009-07-30 Thread Tim Daneliuk
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'

Help with Regex for domain names

2009-07-30 Thread Feyo
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

Re: Newbie needs help with regex strings

2005-12-14 Thread Michael Spencer
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' >

Re: Newbie needs help with regex strings

2005-12-14 Thread Michael Spencer
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

Re: Newbie needs help with regex strings

2005-12-14 Thread Gerard Flanagan
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

Re: Newbie needs help with regex strings

2005-12-14 Thread Dennis Benzinger
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

Re: Newbie needs help with regex strings

2005-12-14 Thread Dennis Benzinger
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'

Re: Newbie needs help with regex strings

2005-12-14 Thread Christopher Subich
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

Re: Newbie needs help with regex strings

2005-12-14 Thread Fredrik Lundh
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

Re: Newbie needs help with regex strings

2005-12-14 Thread Paul McGuire
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

Newbie needs help with regex strings

2005-12-14 Thread Catalina Scott A Contr AFCA/EVEO
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