user775651
user775651

Reputation: 1

Javascript Regex Issue

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

Answers (2)

Arun P Johny
Arun P Johny

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

manojlds
manojlds

Reputation: 301587

There is a / which is unescaped after directoryhere - (\?|/[

(ftp|http|https):\/\/urlhere\.com\/directoryhere(\?|\/[^-+(a-zA-Z)]|$)

Upvotes: 1

Related Questions