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!

2 Answers 2

2

Use lookaround, in this case negative lookahead:

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

and see: Regular expression matching in jQuery

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

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.