0

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.

2 Answers 2

1

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

(ftp|http|https):\/\/urlhere\.com\/directoryhere(\?|\/[^-+(a-zA-Z)]|$)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, used your pattern with the below answer also.
0

You have missed escape one / before [^-+(a-zA-Z)]

Try

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

2 Comments

That just returns null though? Should it not return false?
what does document.referrer returns in your case?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.