Sujet : Re: Correct syntax for pathological re.search()
De : hjp-python (at) *nospam* hjp.at (Peter J. Holzer)
Groupes : comp.lang.pythonDate : 12. Oct 2024, 12:59:58
Autres entêtes
Message-ID : <mailman.21.1728731108.4695.python-list@python.org>
References : 1 2 3 4
Pièces jointes : signature.asc (application/pgp-signature) On 2024-10-11 17:13:07 -0400, AVI GROSS via Python-list wrote:
Is there some utility function out there that can be called to show what the
regular expression you typed in will look like by the time it is ready to be
used?
I assume that by "ready to be used" you mean the compiled form?
No, there doesn't seem to be a way to dump that. You can
p = re.compile("\\sout{")
print(p.pattern)
but that just prints the input string, which you could do without
compiling it first.
But - without having looked at the implementation - it's far from clear
that the compiled form would be useful to the user. It's probably some
kind of state machine, and a large table of state transitions isn't very
readable.
There are a number of websites which visualize regular expressions.
Those are probably better for debugging a regular expression than
anything the re module could reasonably produce (although with the
caveat that such a web site would use a different implementation and
therefore might produce different results).
hp
-- _ | Peter J. Holzer | Story must make more sense than reality.|_|_) | || | | hjp@hjp.at | -- Charles Stross, "Creative writing__/ | http://www.hjp.at/ | challenge!"