I have a question regarding creating a regex from a string. The code is in javascript, basically a variable gets a string. I am not sure how to convert the string to the regex. Here is the code
var string = "the code";
var regex = /(the |code )/g;
How can I convert my string to regex using javascript?
use RegExp:
var stringRe = "the code";
var re = new RegExp(stringRe, "g");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With