Created
October 31, 2018 14:12
-
-
Save ChukwuEmekaAjah/e70bf288700a786b273342f1c153e12f to your computer and use it in GitHub Desktop.
Creating a dynamic code regular expression object to match hosts.
This file contains hidden or 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
function hostregexp(val) { | |
var source = !isregexp(val) | |
? String(val).replace(escapeRegExp, escapeReplace).replace(asteriskRegExp, asteriskReplace) | |
: val.source | |
// force leading anchor matching | |
if (source[0] !== '^') { | |
source = '^' + source | |
} | |
// force trailing anchor matching | |
if (!endAnchoredRegExp.test(source)) { | |
source += '$' | |
} | |
return new RegExp(source, 'i') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment