Sujet : Re: Correct syntax for pathological re.search()
De : hjp-python (at) *nospam* hjp.at (Peter J. Holzer)
Groupes : comp.lang.pythonDate : 21. Oct 2024, 20:10:49
Autres entêtes
Message-ID : <mailman.29.1729537858.4695.python-list@python.org>
References : 1 2 3 4 5 6 7 8 9
Pièces jointes : signature.asc (application/pgp-signature) On 2024-10-19 00:15:23 +0200, jak via Python-list wrote:
Peter J. Holzer ha scritto:
As a trivial example, the regular expressions r"\sout{" and r"\sout\{"
are equivalent (the \ before the { is redundant). Yet
re.compile(s).pattern preserves the difference between the two strings.
Allow me to be fussy: r"\sout{" and r"\sout\{" are similar but not
equivalent.
They are. Both will match the 6 character string
0005c \ REVERSE SOLIDUS
00073 s LATIN SMALL LETTER S
0006f o LATIN SMALL LETTER O
00075 u LATIN SMALL LETTER U
00074 t LATIN SMALL LETTER T
0007b { LEFT CURLY BRACKET
If you omit the backslash, the parser will have to determine if the
graph is part of regular expression {n, m} and will take more time.
Yes, that's the parser. But the result of parsing will be the same:
The string will end in a literal backslash.
hp
-- _ | Peter J. Holzer | Story must make more sense than reality.|_|_) | || | | hjp@hjp.at | -- Charles Stross, "Creative writing__/ | http://www.hjp.at/ | challenge!"