possible bug in re expression?

Robin Becker robin at reportlab.com
Mon Apr 28 05:47:54 EDT 2014


On 25/04/2014 19:32, Terry Reedy wrote:
..........
> 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 '}'?
>
well in fact I suspect this is my mistranslation of the original

new RegExp('.{1,' + (+size) + '}', 'g')

my hacked up translator doesn't know what that means. I suspect that (+size) is 
an attempt to force size to an integer prior to it being forced to a string. I 
used to believe that conversion was always written 0-x, but experimentally 
(+"3") ends up as 3 not "3".

Naively, I imagined that re would complain about ambiguous regular expressions, 
but in the regexp world n problems --> n+1 problems almost surely so I should 
have anticipated it :)

Does this in fact that almost any broken regexp specification will silently fail 
because re will reset and consider any metacharacter as literal?
-- 
Robin Becker




More information about the Python-list mailing list