【发布时间】:2019-01-17 12:00:58
【问题描述】:
我正在寻找 python 中正则表达式的特殊用途。我找到了一些类似的解决方案,但不知道如何使它们适应这种情况。
我想知道如何使用正则表达式拆分以下字符串:
s = '(some, word), (someword), (some other, word)'
为了获得:
['(some, word)', '(someword)', '(some other, word)']
我虽然使用), 作为分隔符,但我不知道如何在拆分后保留)。我怎么能这样做?
这是我的尝试:
re.split('\),', s)
['(some, word', ' (someword', ' (some other, word)']
【问题讨论】: