jamadden / mrab-regex-hg

Automatically exported from code.google.com/p/mrab-regex-hg
0 stars 2 forks source link

conditional patterns #73

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,
while checking the conditionals 
(partly based on 
http://www.asiteaboutnothing.net/regexp/regex-conditionals.html )
in regex I noticed a difference to re (which, I believe, has the expected 
behaviour, unless I made some mistake); cf.:

>>> [m.group() for m in regex.finditer(r"(fe)?male: h(?(1)(er)|(is)) (\w+)", 
"female: her dog; male: his cat. asdsasda")]
['male: his cat']
>>> [m.group() for m in re.finditer(r"(fe)?male: h(?(1)(er)|(is)) (\w+)", 
"female: her dog; male: his cat. asdsasda")]
['female: her dog', 'male: his cat']
>>> 

However, it seem weird, as I am not able to find a difference to another 
(equivalent?) pattern, which works ok in both re and regex:
( http://www.regular-expressions.info/conditional.html )

>>> [m.group() for m in regex.finditer(r"(a)?b(?(1)(c)|(d))", " abc bc bd abd 
")]
['abc', 'bd', 'bd']
>>> [m.group() for m in re.finditer(r"(a)?b(?(1)(c)|(d))", " abc bc bd abd ")]
['abc', 'bd', 'bd']
>>> 

The other conditionals mentioned on those pages (condition with a lookaround 
and checking for recursion) aren't supported in re or regex (the former is 
probably also redundant in regex with unlimited lookaround, is it true?

(regex-0.1.20120705, py 2.7.3, win 7)

regards,
 vbr

Original issue reported on code.google.com by Vlastimil.Brom@gmail.com on 8 Jul 2012 at 1:10

GoogleCodeExporter commented 9 years ago
Fixed in regex-0.1.20120708.

Original comment by re...@mrabarnett.plus.com on 8 Jul 2012 at 6:44