我有一个字符串,如代码所示。我希望得到最终结果:[' AA',' BB',' CC']。 但我在这里得到的是[' AA',' BB']。你能给我一些建议吗?谢谢。
s = "AA-ZZ, BB+ZZ, CC"
a = re.findall(r'(\w+)[-|\\+\\]\w',s)
答案 0 :(得分:0)
使用预测来查看字符串是在+
,-
还是end of string
之前。
a = re.findall(r'(\w+)(?=[-+]|$)',s)