Regular Expression bug?
avi.e.gross at gmail.com
avi.e.gross at gmail.com
Thu Mar 2 17:40:36 EST 2023
José,
Matching can be greedy. Did it match to the last space?
What you want is a pattern that matches anything except a space (or whitespace) followed b matching a space or something similar.
Or use a construct that makes matching non-greedy.
Avi
-----Original Message-----
From: Python-list <python-list-bounces+avi.e.gross=gmail.com at python.org> On Behalf Of jose isaias cabrera
Sent: Thursday, March 2, 2023 2:23 PM
To: python-list at python.org
Subject: Regular Expression bug?
Greetings.
For the RegExp Gurus, consider the following python3 code:
<code>
import re
s = "pn=align upgrade sd=2023-02-"
ro = re.compile(r"pn=(.+) ")
r0=ro.match(s)
>>> print(r0.group(1))
align upgrade
</code>
This is wrong. It should be 'align' because the group only goes up-to the space. Thoughts? Thanks.
josé
--
What if eternity is real? Where will you spend it? Hmmmm...
--
https://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list