Re: Newbie Need Help On Regex!

2016-10-10 Thread breamoreboy
On Monday, October 10, 2016 at 3:58:56 PM UTC+1, infos...@gmail.com wrote: > Hey guys! > > I am new to learning regex in python and I'm wondering how do I use regex in > python to store the integers(positive and negative) i want into a list! > > For e.g. > > This is the data in a list. >

Newbie Need Help On Regex!

2016-10-10 Thread infosecflag
Hey guys! I am new to learning regex in python and I'm wondering how do I use regex in python to store the integers(positive and negative) i want into a list! For e.g. This is the data in a list. [u'\x1b[0m[\x1b[1m\x1b[0m\xbb\x1b[0m\x1b[36m]\x1b[0m (A=-5,B=5)',

Newbie Need Help On Regex!

2016-10-10 Thread infosecflag
Hey guys! I am new to learning regex in python and I'm wondering how do I use regex in python to store the integers(positive and negative) i want into a list! For e.g. This is the data in a list. [u'\x1b[0m[\x1b[1m\x1b[0m\xbb\x1b[0m\x1b[36m]\x1b[0m (A=-5,B=5)',

Re: help with regex

2014-10-08 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 Number (attempt 1): 1)

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.compile(^.*:(? *)(\d+)$)

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 Chris Rebert
On Mon, Apr 11, 2011 at 10:20 PM, Yuri Slobodyanyuk yuri.slobodyan...@gmail.com 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.'

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

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 yuri.slobodyan...@gmail.com 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('

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

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 yuri.slobodyan...@gmail.com 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

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 needed

2011-04-11 Thread Kushal Kumaran
On Tue, Apr 12, 2011 at 10:50 AM, Yuri Slobodyanyuk yuri.slobodyan...@gmail.com 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

Re: Help with regex needed

2011-04-11 Thread Chris Rebert
On Mon, Apr 11, 2011 at 10:20 PM, Yuri Slobodyanyuk yuri.slobodyan...@gmail.com 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

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

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

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 got the

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 python.l...@tim.thechases.com 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 :)

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 eiusmod

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} dolor sit

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 al...@start.no wrote: I haven't used regexps in Python before, but what I did was (1) look in the documentation, [snip] code import re text = ( Lorem [ipsum] dolor sit amet, consectetur, adipisicing elit, sed do eiusmod

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('[', '{').replace(']', '}')

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

2010-02-07 Thread Anssi Saari
Schif Schaf schifsc...@gmail.com 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

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 al...@start.no wrote: I haven't used regexps in Python before, but what I did was (1) look in the documentation, [snip] code import re text = ( Lorem [ipsum] dolor sit amet, consectetur, adipisicing

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

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

2010-02-07 Thread Schif Schaf
On Feb 7, 8:57 am, Tim Chase python.l...@tim.thechases.com 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

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

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

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 al...@start.no 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

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

Re: Help with regex and optional substring in search string

2009-10-14 Thread Timur Tabi
On Oct 14, 9:51 am, Timur Tabi timur.t...@gmail.com 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:

Re: Help with regex and optional substring in search string

2009-10-14 Thread Zero Piraeus
: 2009/10/14 Timur Tabi timur.t...@gmail.com: 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

Re: Help with regex and optional substring in search string

2009-10-14 Thread Zero Piraeus
: 2009/10/14 Timur Tabi timur.t...@gmail.com: 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. --

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 sche...@gmail.com 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

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

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

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:

Re: Help with regex

2009-08-06 Thread alex23
On Aug 7, 1:35 am, Robert Dailey rcdai...@gmail.com 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

Re: Help with regex

2009-08-06 Thread Robert Dailey
On Aug 6, 11:02 am, MRAB pyt...@mrabarnett.plus.com 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

Re: Help with regex

2009-08-06 Thread MRAB
Robert Dailey wrote: On Aug 6, 11:02 am, MRAB pyt...@mrabarnett.plus.com 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 #

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 length 1 or

Re: Help with regex

2009-08-06 Thread Robert Dailey
On Aug 6, 11:12 am, Roman atra...@gmail.com 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 #,#,#,# The

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 length

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

Re: Help with regex

2009-08-06 Thread John Machin
On Aug 7, 7:23 am, Ethan Furman et...@stoneleaf.us 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:

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 solution is

Re: Help with Regex for domain names

2009-08-02 Thread Aahz
In article mailman.3998.1248989346.8015.python-l...@python.org, MRAB pyt...@mrabarnett.plus.com 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

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 =

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: 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: Help with Regex for domain names

2009-07-30 Thread Feyo
On Jul 30, 11:56 am, MRAB pyt...@mrabarnett.plus.com 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

Re: Help with Regex for domain names

2009-07-30 Thread rurpy
On Jul 30, 9:56 am, MRAB pyt...@mrabarnett.plus.com 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

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')

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

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

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 some

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 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' I

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 separate

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 sugar' I

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. Using the csv

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' I