Reputation: 1178
I have a string something like this:
"q1" = "1" And "q2" = "2" oR "q3" = "3"
I want to split it into a array:
['"q1" = "1"',' And ', '"q2" = "2"',' oR ','"q3" = "3"']
How can I do it with regex?
Thanks!
Upvotes: 0
Views: 51
Reputation: 785058
You can use this regex for splitting with a capture group:
/( (?:and|or) )/i
Code:
const str = `"q1" = "1" And "q2" = "2" oR "q3" = "3"`;
var arr = str.split(/( (?:and|or) )/i);
console.log(arr);
Upvotes: 2