【发布时间】:2017-05-04 21:39:23
【问题描述】:
我有一个 Python 字符串
string = aaa1bbb1ccc1ddd
我想这样拆分
re.split('[split at all occurrences of "1", unless the 1 is followed by a c]', string)
所以结果是
['aaa', 'bbb1ccc', 'ddd']
我该怎么做?
【问题讨论】:
-
使用否定的前瞻断言:
1(?!c)(1 后不跟 c) -
re.split("1(?!c)", "aaa1bbb1ccc1ddd")