1

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!

abatishchev
  • 98,240
  • 88
  • 296
  • 433
kinet
  • 1,790
  • 3
  • 20
  • 32

2 Answers2

2

Use lookaround, in this case negative lookahead:

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

and see: Regular expression matching in jQuery

Community
  • 1
  • 1
morja
  • 8,297
  • 2
  • 39
  • 59
1

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.

Community
  • 1
  • 1
kinet
  • 1,790
  • 3
  • 20
  • 32