[issue40043] Poor RegEx example for (?(id/name)yes-pattern|no-pattern)
New submission from Leon Hampton : Hello, In the 3.7.7 documentation on Regular Expression, the Conditional Construct, (?(id/name)yes-pattern|no-pattern), is discussed. (This is a very thorough document, by the way. Good job!) One example given for the Conditional Construct does not work as described. Specifically, the example gives this matching pattern '(<)?(\w+@\w+(?:\.\w+)+)(?(1)>|$)' and states that it will NOT MATCH the string ' <https://bugs.python.org/issue40043> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue40043] RegExp Conditional Construct (?(id/name)yes-pattern|no-pattern) Problem
Leon Hampton added the comment: Hello, There may be a bug in the implementation of the Conditional Construction of Regular Expressions, namely the (?(id/name)yes-pattern|no-pattern). In the Regular Expression documentation (https://docs.python.org/3.7/library/re.html), in the portion about the Conditional Construct, it gives this sample pattern '(<)?(\w+@\w+(?:\.\w+)+)(?(1)>|$)' and states that the pattern WILL NOT MATCH this string ' RegExp Conditional Construct (?(id/name)yes-pattern|no-pattern) Problem ___ Python tracker <https://bugs.python.org/issue40043> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue40043] RegExp Conditional Construct (?(id/name)yes-pattern|no-pattern) Problem
Leon Hampton added the comment: Matthew Barnett & SilentGhost, Thank you for your prompt responses. (Really prompt. Amazing!) SilentGhost, Regarding your response, I used re.search, not re.match. When I used re.match, the regex failed. When I used re.search, it matched. Here are my tests. Your example (cut-and-pasted): x = re.match(r'(<)?(\w+@\w+(?:\.\w+)+)(?(1)>|$)', '|$)', ' I understand the re.match failing, since it always starts at the beginning of the string, but why did re.search succeed? After failing with the yes-pattern, when the regex engine backtracked to the (<)? did it decide not to match the '<' at all and skip the character? Seems like it. What do you think? I am running Python 3.7 via Spyder 4.1.1 on Windows 10. Respectfully, Leon -- ___ Python tracker <https://bugs.python.org/issue40043> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com