[Python-ideas] Add regex pattern literal p""
malincns at 163.com
Thu Dec 27 06:48:40 EST 2018
We can use this literal to represent a compiled pattern, for example:
['a', 'B', 'c']
>>> compiled = p"(?<=abc)def"
>>> m = compiled.search('abcdef')
>>> rp'\W+'.split('Words, words, words.')
['Words', 'words', 'words', '']
This allows peephole optimizer to store compiled pattern in .pyc file,
we can get performance optimization like replacing constant set by
frozenset in .pyc file.
Then such issue  can be solved perfectly.
 Optimize base64.b16decode to use compiled regex
1, Elevating a class in a module (re.Pattern) to language level, this
sounds not very natural.
This makes Python looks like Perl.
2, We can't use regex module as a drop-in replacement: import regex as re
IMHO, I would like to see regex module be adopted into stdlib after
cutting off its "full case-folding" and "fuzzy matching" features.
 Chris Angelico conceived of "compiled regexes be stored in .pyc
file" in March 2013.
 Ken Hilton conceived of "Give regex operations more sugar" in June 2018.
More information about the Python-ideas