I’ll answer that in a second - I just thought of something. Regular Expressions use “escapes” all the time, and I’m concerned about what KM will do to some of them. For instance, if you have a backslash-n, will it become a newline instead? You’ll probably need to do some experimentation with this. Sounds like a PITA. Better you than me.
Back to your question:
You’ll need to use code like this:
var s = "/te.t/i";
var regexp = eval("new RegExp(" + s + ")");
The first line is just setting up the string, like you might get it from KM. In this case, it’s looking for “te” followed by any character followed by “t”, with the flag for ignore case. It was just the first thing that popped into my mind.
The second line is the thing that does all the work. It creates a new “RegExp” object (which is basically the same thing as if I had just hard-coded /te.t/i with no quotes).
The last line just proves it works.
Of course, there are other ways to do this, but this is the simplest, my long-winded explanation notwithstanding.