_list = ['match','regex','find']
_str = 'find the match and then find the regex later on'
根据 _list,能够将 _str 拆分为:
['find',' the ','match',' and then ','find',' the ','regex',' later on']
请注意,拆分字符串为 substr 的其余部分保留了空间
干杯
使用正则表达式。 re.split
前任:
import re
l = ['match','regex','find']
_str = 'find the match and then find the regex later on'
print([i for i in re.split("("+"|".join(l)+ ")", _str) if i])
输出:
['find', ' the ', 'match', ' and then ', 'find', ' the ', 'regex', ' later on']
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句