我需要使用python根据一些字符集拆分一个字符串。例如
String = "A==B AND B==C OR C!=A OR JP Bank==Chase"我不想基于空格拆分字符串,因为JP和Chase将形成两个不同的单词。因此,我需要根据==、!=、AND、OR进行拆分。预期输出
[A,==,B,AND,B,==,C,OR,C,!=,A,OR,JP Bank,==,Chase]发布于 2015-04-08 16:51:19
是像这样吗?
import re
inStrint = "A==B AND B==C OR C!=A OR JP Bank==Chase"
outList = re.split( '(==|!=|OR|AND)', inString)
outList = map( lambda x: x.strip(), outList)https://stackoverflow.com/questions/29509512
复制相似问题