Skip to content

Instantly share code, notes, and snippets.

@ChukwuEmekaAjah
Created October 31, 2018 14:12
Show Gist options
  • Save ChukwuEmekaAjah/e70bf288700a786b273342f1c153e12f to your computer and use it in GitHub Desktop.
Save ChukwuEmekaAjah/e70bf288700a786b273342f1c153e12f to your computer and use it in GitHub Desktop.
Creating a dynamic code regular expression object to match hosts.
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