RegEx - character not before match

Posted by danneth on Stack Overflow See other posts from Stack Overflow or by danneth
Published on 2011-01-17T13:21:34Z Indexed on 2011/01/17 14:53 UTC
Read the original article Hit count: 158

Filed under:
|

I understand the consepts of RegEx, but this is more or less the first time I've actually been trying to write some myself.

As a part of a project, I'm attempting to parse out strings which match to a certain domain (actually an array of domains, but let's keep it simple).

At first I started out with this:

url.match('www.example.com')

But I noticed I was also getting input like this:

http://www.someothersite.com/page?ref=http://www.example.com

These rows will ofcourse match for www.example.com but I wish to exclude them. So I was thinking along these lines: Only match rows that contain www.example.com, but not after a ? character. This is what I came up with:

var reg = new RegExp("[^\\?]*" + url + "(\\.*)", "gi"); 

This does however not seem to work, any suggestions would be greatly appreciated as I fear I've used what little knowledge I yet possess in the matter.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about regex