Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #70611

Re: possible bug in re expression?

From Terry Reedy <tjreedy@udel.edu>
Subject Re: possible bug in re expression?
Date 2014-04-25 14:32 -0400
References <535A8DB5.4090109@chamonix.reportlab.co.uk>
Newsgroups comp.lang.python
Message-ID <mailman.9507.1398450797.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 4/25/2014 12:30 PM, Robin Becker wrote:
> Whilst translating some javascript code I find that this
>
> A=re.compile('.{1,+3}').findall(p)
>
> doesn't give any error, but doesn't manage to find the strings in p that
> I want len(A)==>0, the correct translation should have been
>
> A=re.compile('.{1,3}').findall(p)
>
> which works fine.
>
> should
>
> re.compile('.{1,+3}')
>
> raise an error? It doesn't on python 2.7 or 3.3.

And it should not because it is not an error. '+' means 'match 1 or more 
occurrences of the preceding re' and the preceding re is ','.

 >>> re.match('a{1,+3}', 'a{1,,,3}').group()
'a{1,,,3}'

I suppose that one could argue that '{' alone should be treated as 
special immediately, and not just when a matching '}' is found, and 
should disable other special meanings. I wonder what JS does if there is 
no matching '}'?

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: possible bug in re expression? Terry Reedy <tjreedy@udel.edu> - 2014-04-25 14:32 -0400
  Re: possible bug in re expression? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-04-26 07:24 +0000

csiph-web