Re: re module: Nothing to repeat, but no sre_constants.error: nothing to repeat ?

2012-02-15 Thread Devin Jeanpierre
On Tue, Feb 14, 2012 at 9:08 PM, MRAB wrote: > There is one place in the re engine where it tries to avoid getting > stuck in an infinite loop because of a zero-width match, but the fix > inadvertently causes another bug. It's described in issue #1647489. Just read the issue. Interesting, didn't

Re: re module: Nothing to repeat, but no sre_constants.error: nothing to repeat ?

2012-02-14 Thread MRAB
On 15/02/2012 01:43, Devin Jeanpierre wrote: On Tue, Feb 14, 2012 at 1:05 PM, MRAB wrote: And yeah, even something as crazy as ()* works, but as soon as it becomes (a*)* it doesn't work. Weird. I think it's a combination of warning the user about something that's pointless, as in the case of "

Re: re module: Nothing to repeat, but no sre_constants.error: nothing to repeat ?

2012-02-14 Thread Devin Jeanpierre
On Tue, Feb 14, 2012 at 1:05 PM, MRAB wrote: >> And yeah, even something as crazy as ()* works, but as soon as it >> becomes (a*)* it doesn't work. Weird. >> > I think it's a combination of warning the user about something that's > pointless, > as in the case of "$*", and producing a pattern which

Re: re module: Nothing to repeat, but no sre_constants.error: nothing to repeat ?

2012-02-14 Thread MRAB
On 14/02/2012 15:53, Devin Jeanpierre wrote: On Tue, Feb 14, 2012 at 10:05 AM, Vlastimil Brom wrote: However, is there any realistic usecase for repeated zero-width anchors? Maybe. There is a repeated zero-width anchor is used in the Python re test suite, which is what made me notice this.

Re: re module: Nothing to repeat, but no sre_constants.error: nothing to repeat ?

2012-02-14 Thread Devin Jeanpierre
On Tue, Feb 14, 2012 at 10:05 AM, Vlastimil Brom wrote: > However, is there any realistic usecase for repeated zero-width anchors? Maybe. There is a repeated zero-width anchor is used in the Python re test suite, which is what made me notice this. I assume that came from some actual use-case. (se

Re: re module: Nothing to repeat, but no sre_constants.error: nothing to repeat ?

2012-02-14 Thread Vlastimil Brom
2012/2/14 Devin Jeanpierre : > Hey Pythonistas, > > Consider the regular expression "$*". Compilation fails with the > exception, "sre_constants.error: nothing to repeat". > > Consider the regular expression "(?=$)*". As far as I know it is > e

Re: re module: Nothing to repeat, but no sre_constants.error: nothing to repeat ?

2012-02-14 Thread Devin Jeanpierre
On Tue, Feb 14, 2012 at 8:20 AM, Vinay Sajip wrote: > $ is a meta character for regular expressions. Use '\$*', which does > compile. I mean for it to be a meta-character. I'm wondering why it's OK for to repeat a zero-width match if it is a zero-width assertion. -- Devin -- http://mail.python

Re: re module: Nothing to repeat, but no sre_constants.error: nothing to repeat ?

2012-02-14 Thread Vinay Sajip
On Feb 14, 4:38 am, Devin Jeanpierre wrote: > Hey Pythonistas, > > Consider the regular expression "$*". Compilation fails with the > exception, "sre_constants.error: nothing to repeat". > > Consider the regular expression "(?=$)*". As far as I know

re module: Nothing to repeat, but no sre_constants.error: nothing to repeat ?

2012-02-13 Thread Devin Jeanpierre
Hey Pythonistas, Consider the regular expression "$*". Compilation fails with the exception, "sre_constants.error: nothing to repeat". Consider the regular expression "(?=$)*". As far as I know it is equivalent. It does not fail to compile. Why the inconsistency? W

Re: Nothing to repeat

2011-01-09 Thread Terry Reedy
On 1/9/2011 11:49 AM, Tom Anderson wrote: Hello everyone, long time no see, This is probably not a Python problem, but rather a regular expressions problem. I want, for the sake of arguments, to match strings comprising any number of occurrences of 'spa', each interspersed by any number of occu

Re: Nothing to repeat

2011-01-09 Thread Martin Gregorie
On Sun, 09 Jan 2011 16:49:35 +, Tom Anderson wrote: > > Any thoughts on what i should do? Do i have to bite the bullet and apply > some cleverness in my pattern generation to avoid situations like this? > This sort of works: import re f = open("test.txt") p = re.compile("(spam*)*") for line

Re: Nothing to repeat

2011-01-09 Thread Ian
On 09/01/2011 17:49, Ian wrote: I think you want to anchor your list, or anything will match. Perhaps My bad - this is better re.compile('^((spa)*(m)*)+$') search finds match in 'spa', 'spaspaspa', 'spammmspa', '' and 'mmm' search fails on 'spats', 'mats' and others. -- http://mail.p

Re: Nothing to repeat

2011-01-09 Thread Ian
ile(pattern, flags) File "/usr/lib/python2.6/re.py", line 245, in _compile raise error, v # invalid expression sre_constants.error: nothing to repeat What's going on here? Why is there nothing to repeat? Is the problem having one *'d term inside another? Now, i could a

Nothing to repeat

2011-01-09 Thread Tom Anderson
ython2.6/re.py", line 245, in _compile raise error, v # invalid expression sre_constants.error: nothing to repeat What's going on here? Why is there nothing to repeat? Is the problem having one *'d term inside another? Now, i could actually rewrite this particular patte