Reputation: 671
Does anyone know why jsHint says this regular expression has a "Bad Escapement"?
var regexp = new RegExp('^http(s)?:\/\/([a-z]+\.)?(' + this.opts.domain + ')', 'ig');
It's complaining about the escaped period \.
The regex still works without escaping the period. My goal is to find if a URL contains a given domain name, http://rubular.com/r/5U7kVjhleu
Upvotes: 0
Views: 269
Reputation: 336418
If you construct a regex from a string, you need to double the backslashes (and you don't need to escape the slashes):
var regexp = new RegExp('^http(s)?://([a-z]+\\.)?(' + this.opts.domain + ')', 'ig');
Upvotes: 1