Χρήστος Γεωργίου (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.
--
__
Χρήστος Γεωργίου (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).
--
__
Χρήστος Γεωργίου (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
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
Χρήστος Γεωργίου (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.
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