Re: + in regular expression

2012-10-09 Thread Duncan Booth
Cameron Simpson wrote: >| Because "\s{6}+" >| has other meanings in different regex syntaxes and the designers didn't >| want confusion? > > I think Python REs are supposed to be Perl compatible; ISTR an opening > sentence to that effect... > I don't know the full history of how regex engines

Re: + in regular expression

2012-10-05 Thread Cameron Simpson
On 05Oct2012 10:27, Evan Driscoll wrote: | I can understand that you can create a grammar that excludes it. [...] | Was it because such patterns often reveal a mistake? For myself, I would consider that sufficient reason. I've seen plenty of languages (C and shell, for example, though they are n

Re: + in regular expression

2012-10-05 Thread MRAB
On 2012-10-05 16:27, Evan Driscoll wrote: On 10/05/2012 04:23 AM, Duncan Booth wrote: A regular expression element may be followed by a quantifier. Quantifiers are '*', '+', '?', '{n}', '{n,m}' (and lazy quantifiers '*?', '+?', '{n,m}?'). There's nothing in the regex language which says you can

Re: + in regular expression

2012-10-05 Thread Evan Driscoll
On 10/05/2012 10:27 AM, Evan Driscoll wrote: On 10/05/2012 04:23 AM, Duncan Booth wrote: A regular expression element may be followed by a quantifier. Quantifiers are '*', '+', '?', '{n}', '{n,m}' (and lazy quantifiers '*?', '+?', '{n,m}?'). There's nothing in the regex language which says you c

Re: Re: + in regular expression

2012-10-05 Thread Evan Driscoll
On 10/05/2012 04:23 AM, Duncan Booth wrote: A regular expression element may be followed by a quantifier. Quantifiers are '*', '+', '?', '{n}', '{n,m}' (and lazy quantifiers '*?', '+?', '{n,m}?'). There's nothing in the regex language which says you can follow an element with two quantifiers. In

Re: + in regular expression

2012-10-05 Thread Duncan Booth
Cameron Simpson wrote: > On 03Oct2012 21:17, Ian Kelly wrote: >| On Wed, Oct 3, 2012 at 9:01 PM, contro opinion >| wrote: >| > why the "\s{6}+" is not a regular pattern? >| >| Use a group: "(?:\s{6})+" > > Yeah, it is probably a precedence issue in the grammar. > "(\s{6})+" is also accepte

Re: + in regular expression

2012-10-04 Thread Cameron Simpson
On 03Oct2012 21:17, Ian Kelly wrote: | On Wed, Oct 3, 2012 at 9:01 PM, contro opinion wrote: | > why the "\s{6}+" is not a regular pattern? | | Use a group: "(?:\s{6})+" Yeah, it is probably a precedence issue in the grammar. "(\s{6})+" is also accepted. -- Cameron Simpson Disclaimer: ERIM

Re: + in regular expression

2012-10-04 Thread Ian Kelly
On Thu, Oct 4, 2012 at 9:44 PM, Saroo Jain wrote: > x3=re.match("\s{6}+",str) > > instead use > x3=re.match("\s{6,}",str) > > This serves the purpose. And also give some food for thought for why the > first one throws an error. That matches six or more spaces, not multiples of six spaces. -- ht

RE: + in regular expression

2012-10-04 Thread Saroo Jain
s@python.org] On Behalf Of Mark Lawrence Sent: Friday, October 05, 2012 3:29 AM To: python-list@python.org Subject: Re: + in regular expression On 04/10/2012 04:01, contro opinion wrote: >>>> str=" gg" >>>> x1=re.match("\s+",str) >>>

Re: Re: + in regular expression

2012-10-04 Thread Evan Driscoll
On 10/04/2012 04:59 PM, Mark Lawrence wrote: why the "\s{6}+" is not a regular pattern? Why are you too lazy to do any research before posting a question? Errr... what? I'm only somewhat familiar with the extra stuff that languages provide in their regexs beyond true regular expressio

Re: + in regular expression

2012-10-04 Thread Mark Lawrence
On 04/10/2012 04:01, contro opinion wrote: str=" gg" x1=re.match("\s+",str) x1 <_sre.SRE_Match object at 0xb7354db0> x2=re.match("\s{6}",str) x2 <_sre.SRE_Match object at 0xb7337f38> x3=re.match("\s{6}+",str) Traceback (most recent call last): File "", line 1, in File "/usr/l

Re: + in regular expression

2012-10-03 Thread Ian Kelly
On Wed, Oct 3, 2012 at 9:01 PM, contro opinion wrote: > why the "\s{6}+" is not a regular pattern? Use a group: "(?:\s{6})+" -- http://mail.python.org/mailman/listinfo/python-list

+ in regular expression

2012-10-03 Thread contro opinion
>>> str=" gg" >>> x1=re.match("\s+",str) >>> x1 <_sre.SRE_Match object at 0xb7354db0> >>> x2=re.match("\s{6}",str) >>> x2 <_sre.SRE_Match object at 0xb7337f38> >>> x3=re.match("\s{6}+",str) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/re.py", line 13

Re: Repeating assertions in regular expression

2012-01-03 Thread Devin Jeanpierre
> Put simply, it doesn't occur often enough to be worth it. The cost > outweighs the potential benefit. I don't buy it. You could backtrack instead of failing for \b+ and \b*, and it would be almost as fast as this optimization. -- Devin On Tue, Jan 3, 2012 at 1:57 PM, MRAB wrote: > On 03/01/20

Re: Repeating assertions in regular expression

2012-01-03 Thread MRAB
On 03/01/2012 09:45, Devin Jeanpierre wrote: \\b\\b and \\b{2} aren't equivalent ? This sounds suspiciously like a bug! Why the wording is "should never" ? Repeating a zero-width assertion is not forbidden, for instance : import re re.compile("\\b\\b\w+\\b\\b") <_sre.SRE_Pattern obje

Re: Repeating assertions in regular expression

2012-01-03 Thread Devin Jeanpierre
> \\b\\b and \\b{2} aren't equivalent ? This sounds suspiciously like a bug! > Why the wording is "should never" ? Repeating a zero-width assertion is not > forbidden, for instance : > import re re.compile("\\b\\b\w+\\b\\b") > <_sre.SRE_Pattern object at 0xb7831140> I believe this

Repeating assertions in regular expression

2012-01-03 Thread candide
The regular expression HOWTO (http://docs.python.org/howto/regex.html#more-metacharacters) explains the following # -- zero-width assertions should never be repeated, because if they match once at a given location, they can obviously be matched an infinite number o

Re: Using ascii numbers in regular expression

2009-04-30 Thread MRAB
Lie Ryan wrote: MRAB wrote: You're almost there: re.subn('\x61','b','') or better yet: re.subn(r'\x61','b','') Wouldn't that becomes a literal \x61 instead of "a" as it is inside raw string? Yes. The re module will understand the \x sequence within a regular expression.

Re: Using ascii numbers in regular expression

2009-04-30 Thread Lie Ryan
MRAB wrote: You're almost there: re.subn('\x61','b','') or better yet: re.subn(r'\x61','b','') Wouldn't that becomes a literal \x61 instead of "a" as it is inside raw string? -- http://mail.python.org/mailman/listinfo/python-list

Re: Using ascii numbers in regular expression

2009-04-28 Thread MRAB
jorma kala wrote: Thanks very much for your reply. What I mean is that I would like to use the ascii number in a regular expression pattern. For instance, if I want to substitute the occurrences of character 'a' for the character 'b' in a string, instead of doing this: re.subn('a','b','')

Re: Using ascii numbers in regular expression

2009-04-28 Thread Chris Rebert
On Tue, Apr 28, 2009 at 4:58 AM, jorma kala wrote: > Thanks very much for your reply. > What I mean is that I would like to use the ascii number in a regular > expression pattern. > For instance, if I want to substitute the occurrences of character 'a' for > the character 'b' in a string, instead

Re: Using ascii numbers in regular expression

2009-04-28 Thread jorma kala
Thanks very much for your reply. What I mean is that I would like to use the ascii number in a regular expression pattern. For instance, if I want to substitute the occurrences of character 'a' for the character 'b' in a string, instead of doing this: re.subn('a','b','') I'd like to specify t

Re: Using ascii numbers in regular expression

2009-04-28 Thread Chris Rebert
On Tue, Apr 28, 2009 at 4:05 AM, jorma kala wrote: > Hi, > > How can I use the ascii number of a character in a regular expression > (module re) instead of the character itself? > Thanks very much I refer you to the chr() and ord() built-in functions, which can certainly be used to solve your pro

Using ascii numbers in regular expression

2009-04-28 Thread jorma kala
Hi, How can I use the ascii number of a character in a regular expression (module re) instead of the character itself? Thanks very much -- http://mail.python.org/mailman/listinfo/python-list

Re: Python and Cyrillic characters in regular expression

2008-09-05 Thread Fredrik Lundh
phasma wrote: string = u"Привет" (u'\u041f\u0440\u0438\u0432\u0435\u0442',) string = u"Hi.Привет" (u'Hi',) the [\w\s] pattern you used matches letters, numbers, underscore, and whitespace. "." doesn't fall into that category, so the "match" method stops when it gets to that character. ma

Re: Python and Cyrillic characters in regular expression

2008-09-05 Thread MRAB
On Sep 5, 12:28 pm, phasma <[EMAIL PROTECTED]> wrote: > string = u"ðÒÉ×ÅÔ" All the characters are letters. > (u'\u041f\u0440\u0438\u0432\u0435\u0442',) > > string = u"Hi.ðÒÉ×ÅÔ" The third character isn't a letter and isn't whitespace. > (u'Hi',) > > On Sep 4, 9:53špm, Fredrik Lundh <[EMAIL PRO

Re: Python and Cyrillic characters in regular expression

2008-09-05 Thread phasma
string = u"Привет" (u'\u041f\u0440\u0438\u0432\u0435\u0442',) string = u"Hi.Привет" (u'Hi',) On Sep 4, 9:53 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > phasma wrote: > > Hi, I'm trying extract all alphabetic characters from string. > > > reg = re.compile('(?u)([\w\s]+)', re.UNICODE) > > buf =

Re: Python and Cyrillic characters in regular expression

2008-09-04 Thread Fredrik Lundh
phasma wrote: Hi, I'm trying extract all alphabetic characters from string. reg = re.compile('(?u)([\w\s]+)', re.UNICODE) buf = re.match(string) But it's doesn't work. If string starts from Cyrillic character, all works fine. But if string starts from Latin character, match returns only Latin

Re: Python and Cyrillic characters in regular expression

2008-09-04 Thread MRAB
On Sep 4, 3:42 pm, phasma <[EMAIL PROTECTED]> wrote: > Hi, I'm trying extract all alphabetic characters from string. > > reg = re.compile('(?u)([\w\s]+)', re.UNICODE) You don't need both (?u) and re.UNICODE: they mean the same thing. This will actually match letters and whitespace. > buf = re.ma

Python and Cyrillic characters in regular expression

2008-09-04 Thread phasma
Hi, I'm trying extract all alphabetic characters from string. reg = re.compile('(?u)([\w\s]+)', re.UNICODE) buf = re.match(string) But it's doesn't work. If string starts from Cyrillic character, all works fine. But if string starts from Latin character, match returns only Latin characters. Plea

Re: Use variable in regular expression

2007-08-02 Thread Steve Holden
[when replying to a mailing list or newsgroup response please make sure you include the list as a recipient, so the whole conversation is available] André Martins wrote: > >> I know I can use a variable in regular expressions. I want to use a >> regex to find something based on the beginning o

Re: Use variable in regular expression

2007-08-02 Thread André Martins
> I know I can use a variable in regular expressions. I want to use a > regex to find something based on the beginning of the string. I am > using yesterday's date to find all of my data from yesterday. > Yesterday's date is 20070731, and assigned to the variable > "yesterday_date". I want to loop

Re: Use variable in regular expression

2007-08-02 Thread Steve Holden
[EMAIL PROTECTED] wrote: > I know I can use a variable in regular expressions. I want to use a > regex to find something based on the beginning of the string. I am > using yesterday's date to find all of my data from yesterday. > Yesterday's date is 20070731, and assigned to the variable > "yesterd

Re: Use variable in regular expression

2007-08-02 Thread Sion Arrowsmith
<[EMAIL PROTECTED]> wrote: >I know I can use a variable in regular expressions. I want to use a >regex to find something based on the beginning of the string. You're coming from a Perl background, right? No-one else would think of using a regexp for such a simple thing. There are two things you n

Re: Use variable in regular expression

2007-08-02 Thread vbr
... > Yesterday's date is 20070731, and assigned to the variable > "yesterday_date". I want to loop thru a directory and find all of the > yesterday's data ONLY IF the feature class has the date at the > BEGINNING of the filename. ... > I can't figure out the > syntax of inserting the "^" into the

Re: Use variable in regular expression

2007-08-02 Thread Antti Rasinen
On 2007-08-02, at 13:43, [EMAIL PROTECTED] wrote: > I know I can use a variable in regular expressions. I want to use a > regex to find something based on the beginning of the string. I am > using yesterday's date to find all of my data from yesterday. > Yesterday's date is 20070731, and assigned

Use variable in regular expression

2007-08-02 Thread CarpeSkium
I know I can use a variable in regular expressions. I want to use a regex to find something based on the beginning of the string. I am using yesterday's date to find all of my data from yesterday. Yesterday's date is 20070731, and assigned to the variable "yesterday_date". I want to loop thru a dir

Re: Typed named groups in regular expression

2007-05-20 Thread Paddy
On May 20, 2:27 am, "Hugo Ferreira" <[EMAIL PROTECTED]> wrote: > Both Paddy (hackish) and McGuire (right tool for the job) ideas sound > very interesting ;-) I'll definitely research on them further. > > Thanks for the support... Hackis, hackISH! Sir, I would have you know that the idea proffered

Re: Typed named groups in regular expression

2007-05-19 Thread Hugo Ferreira
Both Paddy (hackish) and McGuire (right tool for the job) ideas sound very interesting ;-) I'll definitely research on them further. Thanks for the support... On 19 May 2007 04:39:58 -0700, Paul McGuire <[EMAIL PROTECTED]> wrote: > On May 19, 12:32 am, Paddy <[EMAIL PROTECTED]> wrote: > > On May

Re: Typed named groups in regular expression

2007-05-19 Thread Paul McGuire
On May 19, 12:32 am, Paddy <[EMAIL PROTECTED]> wrote: > On May 16, 6:58 pm, "Hugo Ferreira" <[EMAIL PROTECTED]> wrote: > > > Hi! > > > Is it possible to "automagically" coerce the named groups to python types? > > e.g.: > > > >>> type(re.match('(?P\d*)', '123').groupdict()['x']) > > > > > > But w

Re: Typed named groups in regular expression

2007-05-18 Thread Paddy
On May 16, 6:58 pm, "Hugo Ferreira" <[EMAIL PROTECTED]> wrote: > Hi! > > Is it possible to "automagically" coerce the named groups to python types? > e.g.: > > >>> type(re.match('(?P\d*)', '123').groupdict()['x']) > > > > But what I'm looking forward is for the type to be 'int'. > > Cheers! > > H

Re: Typed named groups in regular expression

2007-05-16 Thread Miki
Hello Hugo, > Is it possible to "automagically" coerce the named groups to python types? > e.g.: Not that I know of, however I use the following idiom: match = my_regexp.find(some_string) def t(name, convert=str): return convert(match.group(name)) myint = t("field1", int) HTH, -- Miki <[EM

Re: Typed named groups in regular expression

2007-05-16 Thread Steve Holden
Hugo Ferreira wrote: > Hi! > > Is it possible to "automagically" coerce the named groups to python types? > e.g.: > type(re.match('(?P\d*)', '123').groupdict()['x']) > > > But what I'm looking forward is for the type to be 'int'. > > Cheers! > > Hugo Ferreira So apply the "int()" funct

Typed named groups in regular expression

2007-05-16 Thread Hugo Ferreira
Hi! Is it possible to "automagically" coerce the named groups to python types? e.g.: >>> type(re.match('(?P\d*)', '123').groupdict()['x']) But what I'm looking forward is for the type to be 'int'. Cheers! Hugo Ferreira -- http://mail.python.org/mailman/listinfo/python-list

Re: Match First Sequence in Regular Expression?

2006-01-28 Thread Armin Steinhoff
Alex Martelli wrote: > Christoph Conrad <[EMAIL PROTECTED]> wrote: > > >>Hello Roger, >> >> >>>since the length of the first sequence of the letter 'a' is 2. Yours >>>accepts it, right? >> >>Yes, i misunderstood your requirements. So it must be modified >>essentially to that what Tim Chase wrote:

Re: Match First Sequence in Regular Expression?

2006-01-27 Thread Scott David Daniels
How about: pattern = re.compile('^([^a]|(a+[^ab]))*aaab') Which basically says, "precede with arbitrarily many non-a's or a sequences ending in non-b, then must have 3 as followed by a b." cases = ["xyz123aaabbab", "xayz123aaabab", "xaaayz123aaabab", "xyz123babaaabab", "xyz123aabbaaab

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Alex Martelli
Christoph Conrad <[EMAIL PROTECTED]> wrote: > Hallo Alex, > > >> r = re.compile("[^a]*a{3}b+(a+b*)*") matches = [s for s in > >> listOfStringsToTest if r.match(s)] > > > Unfortunately, the OP's spec is even more complex than this, if we are > > to take to the letter what you just quoted; e.g. aa

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Tim Chase
>> "xyz123aaabbaaabab" >> >> where you have "aaab" in there twice. > > Good suggestion. I assumed that this would be a valid case. If not, the expression would need tweaking. >> ^([^b]|((? > Looks good, although I've been unable to find a good > explanation of the "negative lookbehind" constr

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Roger L. Cauvin
"Tim Chase" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > The below seems to pass all the tests you threw at it (taking the modified > 2nd test into consideration) > > One other test that occurs to me would be > > "xyz123aaabbaaabab" > > where you have "aaab" in there twice. Good

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Tim Chase
The below seems to pass all the tests you threw at it (taking the modified 2nd test into consideration) One other test that occurs to me would be "xyz123aaabbaaabab" where you have "aaab" in there twice. -tkc import re tests = [ ("xyz123aaabbab",True), ("xyz123aabbaaab", False), ("xay

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Roger L. Cauvin
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Roger L. Cauvin wrote: > >> > $ python test.py >> > gotexpected >> > --- >> > accept accept >> > reject reject >> > accept accept >> > reject reject >> > accept accept >> >> Thanks, but the second test ca

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Roger L. Cauvin
"Christos Georgiou" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On Thu, 26 Jan 2006 17:09:18 GMT, rumours say that "Roger L. Cauvin" > <[EMAIL PROTECTED]> might have written: > >>Thanks, but the second test case I listed contained a typo. It should >>have >>contained a sequence

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Fredrik Lundh
Roger L. Cauvin wrote: > > $ python test.py > > gotexpected > > --- > > accept accept > > reject reject > > accept accept > > reject reject > > accept accept > > Thanks, but the second test case I listed contained a typo. It should have > contained a sequence of three of the lette

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Roger L. Cauvin
"Christos Georgiou" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On Thu, 26 Jan 2006 18:01:07 +0100, rumours say that "Fredrik Lundh" > <[EMAIL PROTECTED]> might have written: > >>Roger L. Cauvin wrote: >> >>> Good suggestion. Here are some "test cases": >>> >>> "xyz123aaabbab" a

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Christos Georgiou
On Thu, 26 Jan 2006 17:09:18 GMT, rumours say that "Roger L. Cauvin" <[EMAIL PROTECTED]> might have written: >Thanks, but the second test case I listed contained a typo. It should have >contained a sequence of three of the letter 'a'. The test cases should be: > >"xyz123aaabbab" accept >"xyz123

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Roger L. Cauvin
"Christos Georgiou" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On Thu, 26 Jan 2006 16:26:57 GMT, rumours say that "Roger L. Cauvin" > <[EMAIL PROTECTED]> might have written: > >>"Christos Georgiou" <[EMAIL PROTECTED]> wrote in message >>news:[EMAIL PROTECTED] > >>> On Thu, 26 Ja

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Roger L. Cauvin
"Christos Georgiou" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On Thu, 26 Jan 2006 16:41:08 GMT, rumours say that "Roger L. Cauvin" > <[EMAIL PROTECTED]> might have written: > >>Good suggestion. Here are some "test cases": >> >>"xyz123aaabbab" accept >>"xyz123aabbaab" reject >>

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Christos Georgiou
On Thu, 26 Jan 2006 18:01:07 +0100, rumours say that "Fredrik Lundh" <[EMAIL PROTECTED]> might have written: >Roger L. Cauvin wrote: > >> Good suggestion. Here are some "test cases": >> >> "xyz123aaabbab" accept >> "xyz123aabbaab" reject >> "xayz123aaabab" accept >> "xaaayz123abab" reject >> "xaa

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Roger L. Cauvin
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Roger L. Cauvin wrote: > >> Good suggestion. Here are some "test cases": >> >> "xyz123aaabbab" accept >> "xyz123aabbaab" reject >> "xayz123aaabab" accept >> "xaaayz123abab" reject >> "xaaayz123aaabab" accept > > $ more

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Dave Hansen
On Thu, 26 Jan 2006 16:26:57 GMT in comp.lang.python, "Roger L. Cauvin" <[EMAIL PROTECTED]> wrote: >"Christos Georgiou" <[EMAIL PROTECTED]> wrote in message >news:[EMAIL PROTECTED] [...] >> Is this what you mean? >> >> ^[^a]*(a{3})(?:[^a].*)?$ > >Close, but the pattern should allow "arbitrary seq

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Fredrik Lundh
Roger L. Cauvin wrote: > Good suggestion. Here are some "test cases": > > "xyz123aaabbab" accept > "xyz123aabbaab" reject > "xayz123aaabab" accept > "xaaayz123abab" reject > "xaaayz123aaabab" accept $ more test.py import re print "gotexpected" print "-- " testsuite = ( ("x

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Christos Georgiou
On Thu, 26 Jan 2006 16:41:08 GMT, rumours say that "Roger L. Cauvin" <[EMAIL PROTECTED]> might have written: >Good suggestion. Here are some "test cases": > >"xyz123aaabbab" accept >"xyz123aabbaab" reject >"xayz123aaabab" accept >"xaaayz123abab" reject >"xaaayz123aaabab" accept Applying my last

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Roger L. Cauvin
"Alex Martelli" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Tim Chase <[EMAIL PROTECTED]> wrote: > >> > Sorry for the confusion. The correct pattern should reject >> > all strings except those in which the first sequence of the >> > letter 'a' that is followed by the letter 'b'

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Christos Georgiou
On Thu, 26 Jan 2006 16:26:57 GMT, rumours say that "Roger L. Cauvin" <[EMAIL PROTECTED]> might have written: >"Christos Georgiou" <[EMAIL PROTECTED]> wrote in message >news:[EMAIL PROTECTED] >> On Thu, 26 Jan 2006 14:09:54 GMT, rumours say that "Roger L. Cauvin" >> <[EMAIL PROTECTED]> might have

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Alex Martelli
Christoph Conrad <[EMAIL PROTECTED]> wrote: > Hello Roger, > > > since the length of the first sequence of the letter 'a' is 2. Yours > > accepts it, right? > > Yes, i misunderstood your requirements. So it must be modified > essentially to that what Tim Chase wrote: > > m = re.search('^[^a

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Roger L. Cauvin
"Peter Hansen" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Roger L. Cauvin wrote: >> Sorry for the confusion. The correct pattern should reject all strings >> except those in which the first sequence of the letter 'a' that is >> followed by the letter 'b' has a length of exact

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Roger L. Cauvin
"Tim Chase" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >>>r = re.compile("[^a]*a{3}b+(a+b*)*") >>>matches = [s for s in listOfStringsToTest if r.match(s)] >> >> Wow, I like it, but it allows some strings it shouldn't. For example: >> >> "xyz123aabbaaab" >> >> (It skips over the t

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Peter Hansen
Roger L. Cauvin wrote: > Sorry for the confusion. The correct pattern should reject all strings > except those in which the first sequence of the letter 'a' that is followed > by the letter 'b' has a length of exactly three. > > Hope that's clearer . . . . Examples are a *really* good way to c

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Tim Chase
>>r = re.compile("[^a]*a{3}b+(a+b*)*") >>matches = [s for s in listOfStringsToTest if r.match(s)] > > Wow, I like it, but it allows some strings it shouldn't. For example: > > "xyz123aabbaaab" > > (It skips over the two-letter sequence of 'a' and matches 'bbaaab'.) Anchoring it to the beginnin

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Roger L. Cauvin
"Christos Georgiou" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On Thu, 26 Jan 2006 14:09:54 GMT, rumours say that "Roger L. Cauvin" > <[EMAIL PROTECTED]> might have written: > >>Say I have some string that begins with an arbitrary sequence of >>characters >>and then alternates

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Roger L. Cauvin
"Tim Chase" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >> Sorry for the confusion. The correct pattern should reject >> all strings except those in which the first sequence of the >> letter 'a' that is followed by the letter 'b' has a length of >> exactly three. > > Ah...a little

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Christoph Conrad
Hallo Alex, >> r = re.compile("[^a]*a{3}b+(a+b*)*") matches = [s for s in >> listOfStringsToTest if r.match(s)] > Unfortunately, the OP's spec is even more complex than this, if we are > to take to the letter what you just quoted; e.g. aazaaab SHOULD match, Then it's again "a{3}b", isn't it? Fr

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Alex Martelli
Tim Chase <[EMAIL PROTECTED]> wrote: > > Sorry for the confusion. The correct pattern should reject > > all strings except those in which the first sequence of the > > letter 'a' that is followed by the letter 'b' has a length of > > exactly three. > > Ah...a little more clear. > > r = re

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Tim Chase
> Sorry for the confusion. The correct pattern should reject > all strings except those in which the first sequence of the > letter 'a' that is followed by the letter 'b' has a length of > exactly three. Ah...a little more clear. r = re.compile("[^a]*a{3}b+(a+b*)*") matches = [s

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Roger L. Cauvin
"Sybren Stuvel" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Roger L. Cauvin enlightened us with: >> I'm looking for a regular expression that matches the first, and >> only the first, sequence of the letter 'a', and only if the length >> of the sequence is exactly 3. > > Your req

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Christoph Conrad
Hello Roger, > since the length of the first sequence of the letter 'a' is 2. Yours > accepts it, right? Yes, i misunderstood your requirements. So it must be modified essentially to that what Tim Chase wrote: m = re.search('^[^a]*a{3}b', 'xyz123aabbaaab') Best wishes from germany, Christo

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Christos Georgiou
On Thu, 26 Jan 2006 14:09:54 GMT, rumours say that "Roger L. Cauvin" <[EMAIL PROTECTED]> might have written: >Say I have some string that begins with an arbitrary sequence of characters >and then alternates repeating the letters 'a' and 'b' any number of times, >e.g. > >"xyz123aaabbaaaba

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Roger L. Cauvin
"Alex Martelli" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Tim Chase <[EMAIL PROTECTED]> wrote: > ... >> I'm not quite sure what your intent here is, as the >> resulting find would obviously be "aaa", of length 3. > > But that would also match ''; I think he wants negative

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Roger L. Cauvin
"Christoph Conrad" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hello Roger, > >> I'm looking for a regular expression that matches the first, and only >> the first, sequence of the letter 'a', and only if the length of the >> sequence is exactly 3. > > import sys, re, os > > if _

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Alex Martelli
Tim Chase <[EMAIL PROTECTED]> wrote: ... > I'm not quite sure what your intent here is, as the > resulting find would obviously be "aaa", of length 3. But that would also match ''; I think he wants negative loobehind and lookahead assertions around the 'aaa' part. But then there's the spec

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Tim Chase
> Say I have some string that begins with an arbitrary > sequence of characters and then alternates repeating the > letters 'a' and 'b' any number of times, e.g. > "xyz123aaabbaaabaaaabb" > > I'm looking for a regular expression that matches the > first, and only the first, sequence

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Sybren Stuvel
Roger L. Cauvin enlightened us with: > I'm looking for a regular expression that matches the first, and > only the first, sequence of the letter 'a', and only if the length > of the sequence is exactly 3. Your request is ambiguous: 1) You're looking for the first, and only the first, sequence of

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Christoph Conrad
Hello Roger, > I'm looking for a regular expression that matches the first, and only > the first, sequence of the letter 'a', and only if the length of the > sequence is exactly 3. import sys, re, os if __name__=='__main__': m = re.search('a{3}', 'xyz123aaabbaaaabaaabb') print m

Match First Sequence in Regular Expression?

2006-01-26 Thread Roger L. Cauvin
Say I have some string that begins with an arbitrary sequence of characters and then alternates repeating the letters 'a' and 'b' any number of times, e.g. "xyz123aaabbaaabaaaabb" I'm looking for a regular expression that matches the first, and only the first, sequence of the letter 'a