I am designing a regular expression tester in HTML and JavaScript. The user will enter a regex, a string, and choose the function they want to test with (e.g. search, match,
Use the RegExp object constructor to create a regular expression from a string:
var re = new RegExp("a|b", "i"); // same as var re = /a|b/i;