kinet
kinet

Reputation: 1780

Trouble with string matching syntax in jQuery RegEx

I'm trying to add a class to all links not containing my domain external links.

problem is some links are https, some are missing the http, some have www, etc, so i need to search for "example" in any part of the string...

here's the jQuery that i think is close:

.find("a:not([@href^=http://www.example.com*])")

here's the regex i know i want:

"^[^google]*$"

Thanks!

Upvotes: 1

Views: 759

Answers (2)

kinet
kinet

Reputation: 1780

found the answer...doh, should have searched better. Select <a> which href ends with some string

.find('a:not([href*="google"])').not('[href^=#]').attr({ target: '_blank' });

*= matches anything.

Upvotes: 1

morja
morja

Reputation: 8560

Use lookaround, in this case negative lookahead:

^(?:(?!google).)+$

and see: Regular expression matching in jQuery

Upvotes: 2

Related Questions