This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients ezio.melotti, mrabarnett, r.david.murray, rhettinger, serhiy.storchaka
Date 2017-05-12.08:14:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1494576853.44.0.660813121244.issue30349@psf.upfronthosting.co.za>
In-reply-to
Content
Currently the re module supports only simple sets. They can include literal characters, character ranges, some simple character classes and support the negation. The Unicode standard [1] defines set operations (union, intersection, difference and symmetric difference) and nested sets. Some regular expression engines implemented these features, for example the regex module supports all TR18 features except not-nested POSIX character classes.

If replace the re module with the regex module or add support of these features in the re module and make this syntax enabled by default, this will break some code. It is very unlikely the the regular expression contains duplicated characters ('--', '||', '&&' or '~~'), but nested sets uses just '[', and non-escaped '[' is occurred in character sets in regular expressions (even the stdlib contains several occurrences).

Proposed patch adds FutureWarnings emitted when possible breaking set construct ('--', '||', '&&', '~~' or '[') is occurred in a regular expression. We need one or two releases with a warning before changing syntax. The patch also makes re.escape() escaping '&' and '~' and fixes several regular expression in the stdlib.

Alternatively the support of new set syntax could be enabled by special flag.

I'm not sure that the support of set operations and nested sets is necessary. This complicates the syntax of regular expressions (which already is not simple). Currently set operations can be emulated with lookarounds:

[set1||set2] -- (?:[set1]|[set2])
[set1&&set2] -- [set1](?<=[set2]) or (?=[set1])[set2]
[set1--set2] -- [set1](?<![set2]) or [set1](?<=[^set2]) or (?=[set1])[^set2]
[set1~~set2] -- recursively expand [[set1||set2]--[set1&&set2]]

[1] http://unicode.org/reports/tr18/#Subtraction_and_Intersection
History
Date User Action Args
2017-05-12 08:14:13serhiy.storchakasetrecipients: + serhiy.storchaka, rhettinger, ezio.melotti, mrabarnett, r.david.murray
2017-05-12 08:14:13serhiy.storchakasetmessageid: <1494576853.44.0.660813121244.issue30349@psf.upfronthosting.co.za>
2017-05-12 08:14:13serhiy.storchakalinkissue30349 messages
2017-05-12 08:14:12serhiy.storchakacreate