我有一个类似这样的字符串:
"q1" = "1" And "q2" = "2" oR "q3" = "3"
我想将其拆分为一个数组:
['"q1" = "1"',' And ', '"q2" = "2"',' oR ','"q3" = "3"']
我该如何使用正则表达式?
谢谢!
答案 0 :(得分:2)
您可以使用此正则表达式与捕获组拆分:
/( (?:and|or) )/i
代码:
const str = `"q1" = "1" And "q2" = "2" oR "q3" = "3"`;
var arr = str.split(/( (?:and|or) )/i);
console.log(arr);