Reputation: 1
I'm trying to build a regex to test if the referrer contains a certain url (but includes query parameters etc)
Apologies if it's bad but it's my first attempt:
(ftp|http|https):\/\/urlhere\.com\/directoryhere(\?|/[^-+(a-zA-Z)]|$)
It works perfectly on here: http://gskinner.com/RegExr/
But when I try it in in JavaScript/Firebug using:
document.referrer.match(/(ftp|http|https):\/\/urlhere\.com\/directoryhere(\?|/[^-+(a-zA-Z)]|$)/gi);
I get the error:
SyntaxError: unterminated parenthetical
Any help appreciated.
Upvotes: 0
Views: 394
Reputation: 388436
You have missed escape one /
before [^-+(a-zA-Z)]
Try
document.referrer.match(/(ftp|http|https):\/\/urlhere\.com\/directoryhere(\?|\/[^-+(a-zA-Z)]|$)/gi);
Upvotes: 0
Reputation: 301587
There is a /
which is unescaped after directoryhere - (\?|/[
(ftp|http|https):\/\/urlhere\.com\/directoryhere(\?|\/[^-+(a-zA-Z)]|$)
Upvotes: 1