Skip to content

Instantly share code, notes, and snippets.

@malash
Created October 29, 2015 09:29
Show Gist options
  • Save malash/0e164f658996b631e5d4 to your computer and use it in GitHub Desktop.
Save malash/0e164f658996b631e5d4 to your computer and use it in GitHub Desktop.
将字符串形式保存的正则表达式转为RegExp
var regexStr = rule.regex,
start = regexStr.indexOf('/'),
end = regexStr.lastIndexOf('/'),
source = regexStr.substring(start + 1, end),
flags = regexStr.substring(end + 1, regexStr.length);
if (source.length !== 0) {
var newRegex = new RegExp(source, flags);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment