Created
October 29, 2015 09:29
-
-
Save malash/0e164f658996b631e5d4 to your computer and use it in GitHub Desktop.
将字符串形式保存的正则表达式转为RegExp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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