classification
Title: Introduce a method to concatenate regex patterns
Type: enhancement Stage:
Components: Regular Expressions Versions: Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: THRlWiTi, aleskva, ezio.melotti, mrabarnett, serhiy.storchaka
Priority: normal Keywords:

Created on 2018-05-27 08:53 by aleskva, last changed 2018-05-28 08:16 by serhiy.storchaka.

Messages (2)
msg317787 - (view) Author: Ales Kvapil (aleskva) Date: 2018-05-27 08:53
After removing inline flags (deprecated in https://bugs.python.org/issue22493) piping patterns will not work:
pats = [r'(?m)^line.continues$', r'(?s)begin.*?end']
re.compile('|'.join(pats))


Maybe there should be introduced some method to merge patterns (similar to re.escape)?
msg317829 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-05-28 08:16
This is not trivial task because inline flags with global scope can be occurred in any part of the pattern (although using them not at the start of the pattern is deprecated).

But starting with 3.7 you can use inline flags with local scope. This will allow you to use simple string concatenation.

pats = [r'(?m:^line.continues$)', r'(?s:begin.*?end)']
History
Date User Action Args
2018-05-28 08:16:03serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg317829
2018-05-27 11:19:29THRlWiTisetnosy: + THRlWiTi
2018-05-27 08:53:27aleskvacreate