[issue10139] regex A|B : both A and B match, but B is wrongly preferred

2010-10-19 Thread Christos Georgi ou
Χρήστος Γεωργίου (Christos Georgiou) added the comment: No, my mistake, you did well for closing it. The more explicit version of the explanation: both regex_1 and regex_2 start actually matching at index 1, while regex_3 starts matching at index 0. -- __

[issue10139] regex A|B : both A and B match, but B is wrongly preferred

2010-10-19 Thread Christos Georgi ou
Χρήστος Γεωργίου (Christos Georgiou) added the comment: Georg, please re-open it. Focus on the difference between example regex_1|regex_2 (both matching; regex_1 is used as it should be), and regex_1|regex_3 (both matching; regex_3 is used incorrectly). -- __

[issue10139] regex A|B : both A and B match, but B is wrongly preferred

2010-10-19 Thread Christos Georgi ou
Χρήστος Γεωργίου (Christos Georgiou) added the comment: As I see it, it's more like: >>> re.search('a.*c|a.*|.*c', 'abc').group() producing 'bc' instead of 'abc'. Substitute "(?<=^A)" for "a" and "(?=Z$)" for "c" in the pattern above. In your example, the first part ('bc') does not match th

[issue10139] regex A|B : both A and B match, but B is wrongly preferred

2010-10-19 Thread Georg Brandl
Georg Brandl added the comment: I'm not sure this is valid. First, I think I have a much easier example: >>> import re >>> re.search('bc|abc', 'abc').group() 'abc' I assume you'd expect this to give 'bc' as well. However, for a string s, "search" looks for matches looking at s, then looking

[issue10139] regex A|B : both A and B match, but B is wrongly preferred

2010-10-18 Thread Christos Georgi ou
Χρήστος Γεωργίου (Christos Georgiou) added the comment: For completeness' sake, I also provide the "(?:regex_n)" results: >>> text= 'A***Z' >>> re.compile('(?:(?<=^A).*(?=Z$))').search(text).group(0) # regex_1 '***' >>> re.compile('(?:(?<=^A).*)').search(text).group(0) # regex_2 '***Z' >>> re.

[issue10139] regex A|B : both A and B match, but B is wrongly preferred

2010-10-18 Thread Christos Georgi ou
New submission from Χρήστος Γεωργίου (Christos Georgiou) : This is based on that StackOverflow answer: http://stackoverflow.com/questions/3957164/3963443#3963443. It also applies to Python 2.6 . Searching for a regular expression that satisfies the mentioned SO question (a regular expression