Javascript正则表达式问题
我试图构建一个正则表达式来测试推荐人是否包含某个url(但包括查询参数等) 如果情况不好,我会道歉,但这是我第一次尝试:Javascript正则表达式问题,javascript,regex,Javascript,Regex,我试图构建一个正则表达式来测试推荐人是否包含某个url(但包括查询参数等) 如果情况不好,我会道歉,但这是我第一次尝试: (ftp|http|https):\/\/urlhere\.com\/directoryhere(\?|/[^-+(a-zA-Z)]|$) 它在这里非常有效: 但是,当我在JavaScript/Firebug中尝试时,使用: document.referrer.match(/(ftp|http|https):\/\/urlhere\.com\/directoryhere(
(ftp|http|https):\/\/urlhere\.com\/directoryhere(\?|/[^-+(a-zA-Z)]|$)
它在这里非常有效:
但是,当我在JavaScript/Firebug中尝试时,使用:
document.referrer.match(/(ftp|http|https):\/\/urlhere\.com\/directoryhere(\?|/[^-+(a-zA-Z)]|$)/gi);
我得到一个错误:
SyntaxError:unterminated insertional
感谢您的帮助。有一个
/
在directoryhere-(\?|/[
(ftp|http|https):\/\/urlhere\.com\/directoryhere(\?|\/[^-+(a-zA-Z)]|$)
在
[^-+(a-zA-Z)]
之前,您错过了越狱一次 试一试
但是它只返回null?是否应该返回false?在您的案例中,
说明了什么。referer
返回了什么?谢谢,也使用了您的模式和下面的答案。
document.referrer.match(/(ftp|http|https):\/\/urlhere\.com\/directoryhere(\?|\/[^-+(a-zA-Z)]|$)/gi);