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
如果从字符串构造正则表达式,则需要将反斜杠加倍(并且不需要转义斜杠):
var regexp = new RegExp('^http(s)?://([a-z]+\\.)?(' + this.opts.domain + ')', 'ig');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.