我正在使用带有JavaScript的正则表达式而且我遇到了一个让我回复Invalid quantifier ?
的问题。
这是代码:
if(url.match(new RegExp('^https?://.+/foresee(?:-|_)surveydef\.js(?:\?)(.*)','g')) != null)
我在其他问题上阅读了我需要在\
字符之前添加?
,但它无法修复它...
if(url.match(new RegExp('^https\?://.+/foresee(\?:-|_)surveydef\.js(\?:\?)(.*)','g')) != null)
输入网址为http://marvel.com/
,我只是检查匹配。
答案 0 :(得分:0)
使用以下代码修复它:
if(url.match(new RegExp('^https?://.+/foresee(?:-|_)surveydef\.js(\\?:\?)(.*)','g'))