Recent Posts

Caution: Greetings to all visitors. The site is working in short. Links Please skip the link to view any topic and thank you for visiting
header ads

Passing a variable into a JavaScript RegExp method

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

Post a Comment

0 Comments