Re: the buggy regex in Python

2010-11-25 Thread Yingjie Lan
--- On Thu, 11/25/10, MRAB wrote: > > > Look at the spans: > > >>> for m in re.finditer('((.d.)*)*', 'adb'): >     print(m.span()) > >     > (0, 3) > (3, 3) > > There's an non-empty match followed by an empty match. If you read my first post, it should be apparent that that the empty string

Re: the buggy regex in Python

2010-11-25 Thread MRAB
On 25/11/2010 16:44, Yingjie Lan wrote: --- On Thu, 11/25/10, MRAB wrote: re.findall performs multiple searches, each starting where the previous one finished. The first match started at the start of the string and finished at its end. The second match started at that point (the end of the stri

Re: the buggy regex in Python

2010-11-25 Thread Yingjie Lan
--- On Thu, 11/25/10, MRAB wrote: > re.findall performs multiple searches, each starting where > the previous > one finished. The first match started at the start of the > string and > finished at its end. The second match started at that point > (the end of > the string) and found another match,

Re: the buggy regex in Python

2010-11-25 Thread MRAB
On 25/11/2010 11:32, Yingjie Lan wrote: I know many experts will say I don't have understanding...but let me pay this up front as my tuition. Here are some puzzling results I have got (I am using Python 3, I suppose similar results for python 2). When I do the following, I got an exception:

the buggy regex in Python

2010-11-25 Thread Yingjie Lan
I know many experts will say I don't have understanding...but let me pay this up front as my tuition. Here are some puzzling results I have got (I am using Python 3, I suppose similar results for python 2). When I do the following, I got an exception: >>> re.findall('(d*)*', 'adb') >>> re.finda

Re: Clarify Regex in Python.

2006-09-12 Thread Terry Hancock
[EMAIL PROTECTED] wrote: > After may frustrated attempts I came to know that "match" function > in python re package actually start the matchs at the begining of the > subject, where "search" will find the given pattern any where in the > subject. > > My Problem is, I want to know how can I f

Re: Clarify Regex in Python.

2006-09-12 Thread [EMAIL PROTECTED]
k, people, thanks for ur replys. -- http://mail.python.org/mailman/listinfo/python-list

Re: Clarify Regex in Python.

2006-09-12 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > I know there r many more methods to do the job, I just wonder can we > turnoff the default behaviour of match method. that's not the "default behaviour", that's how match works. if you want search, use search instead. -- http://mail.python.org/mailman/listinfo/pyt

Re: Clarify Regex in Python.

2006-09-12 Thread John Machin
[EMAIL PROTECTED] wrote: > > Erm, is there some specific reason why you can't just use the search > > method? Why does it *have* to be match()? > > > > regards > > Steve > > > I know there r many more methods to do the job, I just wonder can we > turnoff the default behaviour of match method. >

Re: Clarify Regex in Python.

2006-09-12 Thread [EMAIL PROTECTED]
> Erm, is there some specific reason why you can't just use the search > method? Why does it *have* to be match()? > > regards > Steve I know there r many more methods to do the job, I just wonder can we turnoff the default behaviour of match method. Thanks. -- http://mail.python.org/mailman

Re: Clarify Regex in Python.

2006-09-12 Thread Steve Holden
[EMAIL PROTECTED] wrote: > After may frustrated attempts I came to know that "match" function in > python re package actually start the matchs at the begining of the > subject, where "search" will find the given pattern any where in the > subject. > > My Problem is, I want to know how can I force

Re: Clarify Regex in Python.

2006-09-12 Thread A.M. Kuchling
On 12 Sep 2006 05:07:03 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > My Problem is, I want to know how can I force match functions to match > the pattern any location in the subject. i.e I want to turn off before > said behaviour. Use search() instead; that's why the method is th

Clarify Regex in Python.

2006-09-12 Thread [EMAIL PROTECTED]
After may frustrated attempts I came to know that "match" function in python re package actually start the matchs at the begining of the subject, where "search" will find the given pattern any where in the subject. My Problem is, I want to know how can I force match functions to match the pattern

Re: regex in python

2006-05-25 Thread John Machin
On 25/05/2006 7:58 PM, gisleyt wrote: > I'm trying to compile a perfectly valid regex, but get the error > message: > > r = > re.compile(r'([^\d]*)(\d{1,3}\.\d{0,2})?(\d*)(\,\d{1,3}\.\d{0,2})?(\d*)?.*') > Traceback (most recent call last): > File "", line 1, in ? > File "/usr/lib/python2.3/sr

Re: regex in python

2006-05-25 Thread Jim Segrave
In article <[EMAIL PROTECTED]>, gisleyt <[EMAIL PROTECTED]> wrote: >I'm trying to compile a perfectly valid regex, but get the error >message: > > r = >re.compile(r'([^\d]*)(\d{1,3}\.\d{0,2})?(\d*)(\,\d{1,3}\.\d{0,2})?(\d*)?.*') >Traceback (most recent call last): > File "", line 1, in ? > File "

Re: regex in python

2006-05-25 Thread Tim Chase
> r = > re.compile(r'([^\d]*)(\d{1,3}\.\d{0,2})?(\d*)(\,\d{1,3}\.\d{0,2})?(\d*)?.*') ... > sre_constants.error: nothing to repeat The error gives something away (like any good error message should) You're attempting to repeat something that may not exist. In this case, it's the last question-m

regex in python

2006-05-25 Thread gisleyt
I'm trying to compile a perfectly valid regex, but get the error message: r = re.compile(r'([^\d]*)(\d{1,3}\.\d{0,2})?(\d*)(\,\d{1,3}\.\d{0,2})?(\d*)?.*') Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.3/sre.py", line 179, in compile return _compile(patter