我有一个Python字符串
string = aaa1bbb1ccc1ddd
我想这样分割
re.split('[split at all occurrences of "1", unless the 1 is followed by a c]', string)
这样的结果是
['aaa', 'bbb1ccc', 'ddd']
我该怎么做呢?
对正则表达式和re
模块使用负前瞻:
>>> string = 'aaa1bbb1ccc1ddd'
>>> import re
>>> re.split(r"1(?!c)", string)
['aaa', 'bbb1ccc', 'ddd']
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句