How can I pass a variable into a JavaScript RegExp match method?
I have this code:
let rgx = new RegExp(/(?<= )(word1|word2|word3)(?= )/).source;
Code (markup):
What I'd like to do is store 'word1|word2|word3' in a variable, and then integrate it in the code above. I searched Google and tried in multiple ways, but nothing seems to work. As a quick example, the following code doesn't work...
let regex_variable = "word1|word2|word3";
let rgx = new RegExp("/(?<= )(" + regex_variable +...
Code (markup):
Passing a variable into a JavaScript RegExp method
from JavaScript https://ift.tt/2CQ63Vs
via
IFTTT
0 Comments