Perhaps you can do something like this:
var pattern = '/ab*c/gi';
if ((m = /^\/(.*)\/([gim]*)$/i.exec(pattern)) != null) {
restr = m[1], flag = m[2], re = new RegExp(restr, flag)
}
You may need to add processing for special regular expression metacharacters if you want them to be processed literally.
source
share