[Python-ideas] Add regex pattern literal p""

Alexander Heger python at 2sn.net
Sun Dec 30 18:35:49 EST 2018

> What's more, it's a tool that should be used
> with considerable reluctance, because REs are essentially unreadable,
> so every time you use one you're creating a maintenance headache.

Well, it requires some experience to read REs, I have written many, and I
still need to test thoroughly even many basic ones for that they really do
what they are supposed to do.  And then there is the issue that there is
many different implementation, what you have to escape, etc., varies
between python (raw and regular strings), emacs, grep, overleaf, ...

Never mind, my main point is that they return an object that is
qualitatively different from a string, for example, in terms of
concatenation.  I also think it is too specialised, and time-critical
constant REs can be stored in the module body, etc., if need be.  I do that.

But since this is the ideas mailing list, and taking this thread on an
excursion, maybe an "addition" operator could be defined for REs, such that

re.compile(s1 + s1) == re.compile(s1) + re.compile(s2)

with the restriction that s1 and s2 are strings that are valid REs each.

Even that would leave questions about how to deal with compile flags; they
probably should be treated the same as if they were embedded at the
beginning of each string.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20181231/efec6b97/attachment.html>

More information about the Python-ideas mailing list