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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.