Reputation: 14096
var re = "^abc";
How to create a RegEx from this variable to be able to test some strings with it like this:
/THE_re_VARIABLE_HERE/i.test( someString );
Upvotes: 0
Views: 61
Reputation: 85545
You can use RegExp method:
var re = "^abc";
new RegExp(re,'i').test( someString );
Upvotes: 1
Reputation: 80629
You'll have to use the class constructor:
var re = "^abc";
new RegExp( re, 'i' ).test( someString );
Upvotes: 1