Jump to content

JS:Excluding Matches With Regular Expressions


SuperBlue

Recommended Posts

var CregExp = new RegExp("\\.*" + terms[x] + "\\.*(?!\<a href\=\>.*\<\\a\>)
", "gi");

 

The above RegExp is suposed to match everything else but the links, i tried using the "?!" as suggested by the reference, but either i'm doing it wrong, or it just doesn't work.

 

The whole idea of using JS to do this, is to avoid having to use PHP for something the browser should be fully capable of, I.E. Highlighting search terms.

 

I have managed to create a fully functional highlighting code, but now i would like it to exclude a pattern from its matches, any idea how to complete this?

Link to comment
Share on other sites

I'm not sure, but I would think that regex would match your terms ONLY if they are not followed by a link that matches that negative look-ahead. I think the way you would have to do this is to negate the match for the <a> and </a> tags around your match terms, instead of at the end.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.