Re: regular expression question (re module)

2008-10-16 Thread Philip Semanchuk
On Oct 16, 2008, at 11:25 PM, Steve Holden wrote: Pat wrote: Faheem Mitha wrote: Hi, I need to match a string of the form capital_letter underscore capital_letter number against a string of the form anything capital_letter underscore capital_letter number some_stuff_not_starting with a nu

Re: regular expression question (re module)

2008-10-16 Thread Steve Holden
Pat wrote: > Faheem Mitha wrote: >> Hi, >> >> I need to match a string of the form >> >> capital_letter underscore capital_letter number >> >> against a string of the form >> >> anything capital_letter underscore capital_letter number >> some_stuff_not_starting with a number >> > >> DUKE1_plat

Re: regular expression question (re module)

2008-10-16 Thread Pat
Faheem Mitha wrote: Hi, I need to match a string of the form capital_letter underscore capital_letter number against a string of the form anything capital_letter underscore capital_letter number some_stuff_not_starting with a number DUKE1_plateD_A12.CEL. Thanks in advance. Please cc

Re: regular expression question (re module)

2008-10-11 Thread bearophileHUGS
Faheem Mitha: > I need to match a string of the form > ... Please, show the code you have written so far, with your input-output examples included (as doctests, for example), and we can try to find ways to help you remove the bugs you have. Bye, bearophile -- http://mail.python.org/mailman/listin

Re: Regular Expression question

2007-10-25 Thread looping
On Oct 25, 9:25 am, Peter Otten <[EMAIL PROTECTED]> wrote: > > You want a "negative lookahead assertion" then: > Now I feel dumb... I've seen the (?!...) dozen times in the doc but never figure out that it is what I'm looking for. So this one is the winner: s = re.search(r'create\s+or\s+replace\s

Re: Regular Expression question

2007-10-25 Thread Peter Otten
looping wrote: > On Oct 25, 8:49 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: >> >> needle = re.compile(r'create\s+or\s+replace\s+package(\s+body)?\s+', >> re.IGNORECASE) > > What I want here is a RE that return ONLY the line without the "body" > keyword. > Your RE

Re: Regular Expression question

2007-10-25 Thread looping
On Oct 25, 8:49 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > > needle = re.compile(r'create\s+or\s+replace\s+package(\s+body)?\s+', > re.IGNORECASE) What I want here is a RE that return ONLY the line without the "body" keyword. Your RE return both. I know I could u

Re: Regular Expression question

2007-10-24 Thread Marc 'BlackJack' Rintsch
On Thu, 25 Oct 2007 06:34:03 +, looping wrote: > Hi, > It's not really a Python question but I'm sure someone could help me. > > When I use RE, I always have trouble with this kind of search: > > Ex. > > I've a text file: > """ > create or replace package XXX > ... > > create or replace pa

Re: Regular Expression question

2006-08-22 Thread Anthra Norell
cases all of which you need to handle? Frederic - Original Message - From: <[EMAIL PROTECTED]> Newsgroups: comp.lang.python To: Sent: Monday, August 21, 2006 11:35 PM Subject: Re: Regular Expression question > Hi, thanks everyone for the information! Still going through it

Re: Regular Expression question

2006-08-21 Thread stevebread
Hi, thanks everyone for the information! Still going through it :) The reason I did not match on tag2 in my original expression (and I apologize because I should have mentioned this before) is that other tags could also have an attribute with the value of "adj__" and the attribute name may not be

Re: Regular Expression question

2006-08-21 Thread Rob Wolfe
[EMAIL PROTECTED] wrote: > got zero results on this one :) Really? >>> s = ''' ''' >>> pat = re.compile('tag1.+?name="(.+?)".*?(?:<)(?=tag2).*?="adj__(.*?)__', >>> re.DOTALL) >>> m = re.findall(pat, s) >>> m [('john', 'tall'), ('joe', 'short')] Regards, Rob -- http://mail.python.org/m

Re: Regular Expression question

2006-08-21 Thread Paul McGuire
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi, I am having some difficulty trying to create a regular expression. > > Consider: > > > > > > > Whenever a tag1 is followed by a tag 2, I want to retrieve the values > of the tag1:name and tag2:value attributes. So my end resul

Re: Regular Expression question

2006-08-21 Thread Neil Cerutti
On 2006-08-21, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hi, I am having some difficulty trying to create a regular expression. > > Consider: > > > > > > > Whenever a tag1 is followed by a tag 2, I want to retrieve the > values of the tag1:name and tag2:value attributes. So my end > result

Re: Regular Expression question

2006-08-21 Thread Paddy
[EMAIL PROTECTED] wrote: > Hi, I am having some difficulty trying to create a regular expression. Steve, I find this tool is great for debugging regular expressions. http://kodos.sourceforge.net/ Just put some sample text in one window, your trial RE in another, and Kodos displays a wealth of

Re: Regular Expression question

2006-08-21 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > Hi, I am having some difficulty trying to create a regular expression. > > Consider: > > > > > > > Whenever a tag1 is followed by a tag 2, I want to retrieve the values > of the tag1:name and tag2:value attributes. So my end result here > should be > john, tal

Re: Regular Expression question

2006-08-21 Thread stevebread
got zero results on this one :) -- http://mail.python.org/mailman/listinfo/python-list

Re: Regular Expression question

2006-08-21 Thread Rob Wolfe
[EMAIL PROTECTED] wrote: > Thanks, i just tried it but I got the same result. > > I've been thinking about it for a few hours now and the problem with > this approach is that the .*? before the (?=tag2) may have matched a > tag1 and i don't know how to detect it. Maybe like this: 'tag1.+?name="(.

Re: Regular Expression question

2006-08-21 Thread bearophileHUGS
I am not expert of REs yet, this my first possible solution: import re txt = """ """ tfinder = r"""<# The opening < the tag to find \s* # Possible space or newline (tag[12]) # First subgroup, the identifier, tag1 or tag2

Re: Regular Expression question

2006-08-21 Thread stevebread
Thanks, i just tried it but I got the same result. I've been thinking about it for a few hours now and the problem with this approach is that the .*? before the (?=tag2) may have matched a tag1 and i don't know how to detect it. And even if I could, how would I make the search reset its start pos

Re: Regular Expression question

2006-08-21 Thread Rob Wolfe
[EMAIL PROTECTED] wrote: > Hi, I am having some difficulty trying to create a regular expression. > > Consider: > > > > > > > Whenever a tag1 is followed by a tag 2, I want to retrieve the values > of the tag1:name and tag2:value attributes. So my end result here > should be > john, tall >

Re: Regular Expression question

2006-06-08 Thread Duncan Booth
Paul McGuire wrote: >> import re >> r=re.compile('[^"]+)"[^>]*>',re.IGNORECASE) >> for m in r.finditer(html): >> print m.group('image') >> > > Ouch - this fails to match any tag that has some other > attribute, such as "height" or "width", before the "src" attribute. > www.yahoo.com has sev

Re: Regular Expression question

2006-06-07 Thread Paul McGuire
"Frank Potter" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > pyparsing is cool. > but use only re is also OK > # -*- coding: UTF-8 -*- > import urllib2 > html=urllib2.urlopen(ur"http://www.yahoo.com/";).read() > > import re > r=re.compile('[^"]+)"[^>]*>',re.IGNORECASE) > for m in r.

Re: Regular Expression question

2006-06-07 Thread Frank Potter
pyparsing is cool. but use only re is also OK # -*- coding: UTF-8 -*- import urllib2 html=urllib2.urlopen(ur"http://www.yahoo.com/";).read() import re r=re.compile('[^"]+)"[^>]*>',re.IGNORECASE) for m in r.finditer(html): print m.group('image') I got these rusults: http://us.i1.yimg.com/us.yi

Re: Regular Expression question

2006-06-07 Thread Paul McGuire
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi, > I am new to python regular expression, I would like to use it to get an > attribute of an html element from an html file? > > for example, I was able to read the html file using this: >req = urllib2.Request(url=acaURL) > f

Re: Re: Regular Expression question

2006-06-07 Thread 李政
I'm sorry! I mean pattern is an argument of the function, in this case, how I process special charactors.    patter = 'www.'   # not this     if re.compile(pattern).match(string) is not None:     ..   but not:       if re.compile(r'www.').match(string) is not None

Re: Regular Expression question

2006-06-07 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > I am new to python regular expression, I would like to use it to get an > attribute of an html element from an html file? if you want to parse HTML, use an HTML parser. if you want to parse sloppy HTML, use a tolerant HTML parser: http://www.crummy.com/software/

Re: Regular Expression question

2005-12-01 Thread Fredrik Lundh
Michelle McCall wrote: >I have a script that needs to scan every line of a file for numerous > strings. There are groups of strings for each "area" of data we are looking > for. Looping through each of these list of strings separately for each line > has slowed execution to a crawl. Can I creat

Re: Regular expression question -- exclude substring

2005-11-07 Thread Bengt Richter
On Mon, 7 Nov 2005 16:38:11 -0800, James Stroud <[EMAIL PROTECTED]> wrote: >On Monday 07 November 2005 16:18, [EMAIL PROTECTED] wrote: >> Ya, for some reason your non-greedy "?" doesn't seem to be taking. >> This works: >> >> re.sub('(.*)(00.*?01) target_mark', r'\2', your_string) > >The non-greed

Re: Regular expression question -- exclude substring

2005-11-07 Thread James Stroud
On Monday 07 November 2005 17:31, Kent Johnson wrote: > James Stroud wrote: > > On Monday 07 November 2005 16:18, [EMAIL PROTECTED] wrote: > >>Ya, for some reason your non-greedy "?" doesn't seem to be taking. > >>This works: > >> > >>re.sub('(.*)(00.*?01) target_mark', r'\2', your_string) > > > >

Re: Regular expression question -- exclude substring

2005-11-07 Thread Kent Johnson
James Stroud wrote: > On Monday 07 November 2005 16:18, [EMAIL PROTECTED] wrote: > >>Ya, for some reason your non-greedy "?" doesn't seem to be taking. >>This works: >> >>re.sub('(.*)(00.*?01) target_mark', r'\2', your_string) > > > The non-greedy is actually acting as expected. This is because

Re: Regular expression question -- exclude substring

2005-11-07 Thread James Stroud
On Monday 07 November 2005 16:18, [EMAIL PROTECTED] wrote: > Ya, for some reason your non-greedy "?" doesn't seem to be taking. > This works: > > re.sub('(.*)(00.*?01) target_mark', r'\2', your_string) The non-greedy is actually acting as expected. This is because non-greedy operators are "forwar

Re: Regular expression question -- exclude substring

2005-11-07 Thread google
Ya, for some reason your non-greedy "?" doesn't seem to be taking. This works: re.sub('(.*)(00.*?01) target_mark', r'\2', your_string) -- http://mail.python.org/mailman/listinfo/python-list

Re: Regular expression question -- exclude substring

2005-11-07 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > Hi, > > I'm having trouble extracting substrings using regular expression. Here > is my problem: > > Want to find the substring that is immediately before a given > substring. For example: from > "00 noise1 01 noise2 00 target 01 target_mark", > want to get > "00 target

Re: regular expression question

2005-02-14 Thread Fredrik Lundh
Bruno Desthuilliers wrote: >> match = STX + '(.*)' + ETX >> >> # Example 1 >> # This appears to work, but I'm not sure if the '+' is being used in >> the regular expression, or if it's just joining STX, '(.*)', and ETX. >> >> if re.search(STX + '(.*)' + ETX,data): >> print "Matches" >> >> # Exam

Re: regular expression question

2005-02-14 Thread snacktime
> You may want something like: > if re.search('%s(.*)%s' % (STX, ETX), data): > Ah I didn't even think about that... Chris -- http://mail.python.org/mailman/listinfo/python-list

Re: regular expression question

2005-02-14 Thread Bruno Desthuilliers
snacktime a écrit : The primary question is how do I perform a match when the regular expression contains string variables? For example, in the following code I want to match a line that starts with STX, then has any number of characters, then ends with STX. Example 2 I'm pretty sure works as I ex