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

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Dec 30 17:55:34 EST 2018


Steven D'Aprano wrote:
> _t1 = re.compile(r"(\d)\1")  # compile-time
> _t2 = re.compile(r"(\s)\1")  # compile-time
> re.compile(_t1.pattern + _t2.pattern)  # run-time

It would be weird if p"(\d)\1" + p"(\s)\1" worked but
re.compile(r"(\d)\1") + re.compile(r"(\s)\1") didn't.

-- 
Greg


More information about the Python-ideas mailing list