Anonymous user
Multisplit: Difference between revisions
m
→Using Regular expressions: handle edge cases consistently.
(→{{header|Python}}: Add RE version) |
m (→Using Regular expressions: handle edge cases consistently.) |
||
Line 51:
<lang python>>>> import re
>>> def ms2(txt="a!===b=!=c", sep=["==", "!=", "="]):
if not txt or not sep:
ans = []▼
return []
▲ ans = m = []
for m in re.finditer('(.*?)(?:' + '|'.join('('+re.escape(s)+')' for s in sep) + ')', txt):
ans += [m.group(1), (m.lastindex-2, m.start(m.lastindex))]
if m and txt[m.end(m.lastindex):]:
ans += [txt[m.end(m.lastindex):]]
return ans
|