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