我想使用正则表达式拆分字符串,并在结果数组中包含分隔符/匹配信息.
在java中我用过:
theString.split("(?<=[!><=}{])|(?=[!><=}{])|(?<= AND )|(?= AND )|(?<= OR )|(?= OR )")
Run Code Online (Sandbox Code Playgroud)
但是,javascript不支持lookbehind ?<=
例如,我想要字符串:
"Reason={Existing problem or fault}{Bestaande probleem of vout}{Other}{Ander} and Required!=No and Results >=10 and Results <=25 and Tst>5 and Tst<80 and Info=test this or that and those and Success!=Yes"
Run Code Online (Sandbox Code Playgroud)
分开:
Reason,=,{,Existing problem, or ,fault,},{,Bestaande probleem of vout,},{,Other,},{,Ander,}, and ,Required,!,=,No, and ,Results,>,=,10, and ,Results,<,=,25, and ,Tst,>,5, and ,Tst,<,80, and ,Info,=,test this, or ,that, and ,those, and ,Success,!,=,Yes
Run Code Online (Sandbox Code Playgroud)
我得到的例子:
var thestr = "Reason={Existing problem or fault}{Bestaande probleem of vout}{Other}{Ander} …Run Code Online (Sandbox Code Playgroud)