You can create a regular expression from a string:
code:
// Create a string to store the pattern of our regular expression
var sRegExp = "[abc]+";
// Create a RegExp object with the pattern as sRegExp and the flags as "i" (case insensitivity)
var rRegExp = new RegExp(sRegExp, "i");
You can insert variables in the string.