Re: A regular expression question

2016-09-28 Thread Ben Finney
Cpcp Cp writes: > Look this > > >>> import re > >>> text="asdfnbd]" > >>> m=re.sub("n*?","?",text) > >>> print m > ?a?s?d?f?n?b?d?]? > > I don't understand the 'non-greedy' pattern. Since ‘n*’ matches zero or more ‘n’s, it matches zero adjacent to every actual character. It's

A regular expression question

2016-09-28 Thread Cpcp Cp
Look this >>> import re >>> text="asdfnbd]" >>> m=re.sub("n*?","?",text) >>> print m ?a?s?d?f?n?b?d?]? I don't understand the 'non-greedy' pattern. I think the repl argument should replaces every char in text and outputs "". -- https://mail.python.org/mailman/listinfo/python-list

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 snip DUKE1_plateD_A12.CEL. Thanks in advance.

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 snip DUKE1_plateD_A12.CEL. Thanks

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

regular expression question (re module)

2008-10-11 Thread Faheem Mitha
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 Eg D_A1 needs to match with DUKE1_plateD_A1.CEL, but not any of

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

Regular Expression question

2007-10-25 Thread looping
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 package body XXX ... now I want to search the position (line) of this two string.

Re: Regular Expression question

2007-10-25 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 package body XXX

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 use it

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 return both.

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 =

Python regular expression question!

2006-09-20 Thread unexpected
I'm trying to do a whole word pattern match for the term 'MULTX-' Currently, my regular expression syntax is: re.search(('^')+(keyword+'\\b') where keyword comes from a list of terms. ('MULTX-' is in this list, and hence a keyword). My regular expression works for a variety of different

Re: Python regular expression question!

2006-09-20 Thread Hallvard B Furuseth
unexpected [EMAIL PROTECTED] writes: I'm trying to do a whole word pattern match for the term 'MULTX-' Currently, my regular expression syntax is: re.search(('^')+(keyword+'\\b') \b matches the beginning/end of a word (characters a-zA-Z_0-9). So that regex will match e.g. MULTX-FOO but not

Re: Python regular expression question!

2006-09-20 Thread unexpected
\b matches the beginning/end of a word (characters a-zA-Z_0-9). So that regex will match e.g. MULTX-FOO but not MULTX-. So is there a way to get \b to include - ? -- http://mail.python.org/mailman/listinfo/python-list

Re: Python regular expression question!

2006-09-20 Thread Ant
unexpected wrote: \b matches the beginning/end of a word (characters a-zA-Z_0-9). So that regex will match e.g. MULTX-FOO but not MULTX-. So is there a way to get \b to include - ? No, but you can get the behaviour you want using negative lookaheads. The following regex is effectively \b

Re: Python regular expression question!

2006-09-20 Thread unexpected
Sweet! Thanks so much! -- http://mail.python.org/mailman/listinfo/python-list

Re: Regular Expression question

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

Regular Expression question

2006-08-21 Thread stevebread
Hi, I am having some difficulty trying to create a regular expression. Consider: tag1 name=john/ br/ tag2 value=adj__tall__/ tag1 name=joe/ tag1 name=jack/ tag2 value=adj__short__/ Whenever a tag1 is followed by a tag 2, I want to retrieve the values of the tag1:name and tag2:value attributes.

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: tag1 name=john/ br/ tag2 value=adj__tall__/ tag1 name=joe/ tag1 name=jack/ tag2 value=adj__short__/ Whenever a tag1 is followed by a tag 2, I want to retrieve the values of the

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

Re: Regular Expression question

2006-08-21 Thread bearophileHUGS
I am not expert of REs yet, this my first possible solution: import re txt = tag1 name=john/ br/ tag2 value=adj__tall__/ tag1 name=joe/ tag1 name=jack/ tag2 value=adj__short__/ tfinder = r# The opening the tag to find \s* # Possible space or newline

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:

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 Fredrik Lundh
[EMAIL PROTECTED] wrote: Hi, I am having some difficulty trying to create a regular expression. Consider: tag1 name=john/ br/ tag2 value=adj__tall__/ tag1 name=joe/ tag1 name=jack/ tag2 value=adj__short__/ Whenever a tag1 is followed by a tag 2, I want to retrieve the values of the

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 Neil Cerutti
On 2006-08-21, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi, I am having some difficulty trying to create a regular expression. Consider: tag1 name=john/ br/ tag2 value=adj__tall__/ tag1 name=joe/ tag1 name=jack/ tag2 value=adj__short__/ Whenever a tag1 is followed by a tag 2, I want to

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: tag1 name=john/ br/ tag2 value=adj__tall__/ tag1 name=joe/ tag1 name=jack/ tag2 value=adj__short__/ Whenever a tag1 is followed by a tag 2, I want

Re: Regular Expression question

2006-08-21 Thread Rob Wolfe
[EMAIL PROTECTED] wrote: got zero results on this one :) Really? s = '''tag1 name=john/ br/ tag2 value=adj__tall__/ tag1 name=joe/ tag1 name=jack/ tag2 value=adj__short__/''' pat = re.compile('tag1.+?name=(.+?).*?(?:)(?=tag2).*?=adj__(.*?)__', re.DOTALL) m = re.findall(pat, s) m

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

Regular Expression question

2006-06-07 Thread ken . carlino
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 = urllib2.urlopen(req) data = f.read() my question is how can I

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:

Re: Re: Regular Expression question

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

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: 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(urhttp://www.yahoo.com/;).read() import re r=re.compile('img\s+src=(?Pimage[^]+)[^]*',re.IGNORECASE) for m in r.finditer(html): print m.group('image') I got these rusults:

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(urhttp://www.yahoo.com/;).read() import re r=re.compile('img\s+src=(?Pimage[^]+)[^]*',re.IGNORECASE) for m in

Regular Expression question

2005-12-01 Thread Michelle McCall
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 create ONE regular expression from a

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 create ONE

Regular expression question -- exclude substring

2005-11-07 Thread dreamerbin
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 01 which is before target_mark. My regular

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 01 which

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 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 forward

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 non-greedy

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) The non-greedy is

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-greedy is actually

Hopefully simple regular expression question

2005-06-14 Thread [EMAIL PROTECTED]
I want to match a word against a string such that 'peter' is found in peter bengtsson or hey peter, or but in thepeter bengtsson or hey peterbe, because the word has to stand on its own. The following code works for a single word: def createStandaloneWordRegex(word): return a regular

Re: Hopefully simple regular expression question

2005-06-14 Thread John Machin
[EMAIL PROTECTED] wrote: I want to match a word against a string such that 'peter' is found in peter bengtsson or hey peter, or but in thepeter bengtsson or hey peterbe, because the word has to stand on its own. The following code works for a single word: def

Re: Hopefully simple regular expression question

2005-06-14 Thread Kalle Anke
On Tue, 14 Jun 2005 13:01:58 +0200, [EMAIL PROTECTED] wrote (in article [EMAIL PROTECTED]): How do I modify my regular expression to match on expressions as well as just single words?? import re def createStandaloneWordRegex(word): return a regular expression that can find 'peter' only

Re: Hopefully simple regular expression question

2005-06-14 Thread TZOTZIOY
On 14 Jun 2005 04:01:58 -0700, rumours say that [EMAIL PROTECTED] [EMAIL PROTECTED] might have written: I want to match a word against a string such that 'peter' is found in peter bengtsson or hey peter, or but in thepeter bengtsson or hey peterbe, because the word has to stand on its own. The

Re: Hopefully simple regular expression question

2005-06-14 Thread [EMAIL PROTECTED]
Thank you! I had totally forgot about that. It works. -- http://mail.python.org/mailman/listinfo/python-list

regular expression question

2005-02-14 Thread snacktime
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 expect, but I'm not

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

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 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 # Example 2 # This also

Simple (newbie) regular expression question

2005-01-21 Thread André Roberge
Sorry for the simple question, but I find regular expressions rather intimidating. And I've never needed them before ... How would I go about to 'define' a regular expression that would identify strings like __alphanumerical__ as in __init__ (Just to spell things out, as I have seen underscores

Re: Simple (newbie) regular expression question

2005-01-21 Thread John Machin
André Roberge wrote: Sorry for the simple question, but I find regular expressions rather intimidating. And I've never needed them before ... How would I go about to 'define' a regular expression that would identify strings like __alphanumerical__ as in __init__ (Just to spell things

Re: Simple (newbie) regular expression question

2005-01-21 Thread André Roberge
John Machin wrote: André Roberge wrote: Sorry for the simple question, but I find regular expressions rather intimidating. And I've never needed them before ... How would I go about to 'define' a regular expression that would identify strings like __alphanumerical__ as in __init__ (Just to spell

OT: novice regular expression question

2004-12-30 Thread It's me
I am never very good with regular expressions. My head always hurts whenever I need to use it. I need to read a data file and parse each data record. Each item on the data record begins with either a string, or a list of strings. I searched around and didn't see any existing Python packages

Re: OT: novice regular expression question

2004-12-30 Thread Steve Holden
It's me wrote: I am never very good with regular expressions. My head always hurts whenever I need to use it. Well, they are a pain to more than just you, and the conventional advice is even when you are convinced you need to use REs, try and find another way. I need to read a data file and

Re: OT: novice regular expression question

2004-12-30 Thread RyanMorillo
check jgsoft dot com, they have2 things witch may help. Edit pad pro (the test version has a good tutorial) or power grep (if you do a lot of regexes, or the mastering regular expressions book from Orielly (if yo do a lot of regex work) Also the perl group would be good for regexes (pythons are

Re: OT: novice regular expression question

2004-12-30 Thread It's me
I'll chew on this. Thanks, got to go. Steve Holden [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] It's me wrote: I am never very good with regular expressions. My head always hurts whenever I need to use it. Well, they are a pain to more than just you, and the conventional

Re: OT: novice regular expression question

2004-12-30 Thread M.E.Farmer
Hello me, Have you tried shlex.py it is a tokenizer for writing lexical parsers. Should be a breeze to whip something up with it. an example of tokenizing: pyimport shlex py# fake an open record pyimport cStringIO pymyfakeRecord = cStringIO.StringIO() pymyfakeRecord.write(['1','2'] \n 'fdfdfdfd'

Re: OT: novice regular expression question

2004-12-30 Thread M.E.Farmer
It's me wrote: The shlex.py needs quite a number of .py files. I tried to hunt down a few of them and got really tire. Is there one batch of .py files that I can download from somewhere? Thanks, Not sure what you mean by this. Shlex is a standard library module. It imports os and sys only,