[New-bugs-announce] [issue29388] regex mismatch in the simple cases

MaxR report at bugs.python.org
Sun Jan 29 21:05:32 EST 2017


New submission from MaxR:

When I compile and match, for example:
pattern = re.compile(r"""    ([a-z]|\d)+$         # ends with letter or number only    """, re.VERBOSE | re.IGNORECASE)
print(re.match(pattern, 'abc'))

result is correct:
<_sre.SRE_Match object; span=(0, 3), match='abc'>

but then I use the same pattern with another string:
print(re.match(pattern, 'abc.fds'))

result is: 
None

I tried to reformulate the pattern to the same, for example:
pattern = re.compile(r"""    (a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|\d)+$         # ends with letter or number only    """, re.VERBOSE | re.IGNORECASE)

or to:
pattern = re.compile(r"""    [a-z\d]+$         # ends with letter or number only    """, re.VERBOSE | re.IGNORECASE)

or to:

pattern = = re.compile(r"""    ([a-z]|\d)+$         # ends with letter or number only    """, re.VERBOSE | re.IGNORECASE)

but the result is all the time the same - None
And еhat is the double strange for the last three pattern - None is result also for 
print(re.match(pattern, 'abc'))

I checked this patterns on the site regex101.com
and all of them should work good and right
It's achtung!

----------
components: Regular Expressions
messages: 286464
nosy: MaxR, ezio.melotti, mrabarnett
priority: normal
severity: normal
status: open
title: regex mismatch in the simple cases
type: behavior
versions: Python 3.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29388>
_______________________________________


More information about the New-bugs-announce mailing list