Help - Search - Members - Calendar
Full Version: how would I select non-linked text in regex?
Invision Power Services > Community Forums > Community Web Design and Coding
Trel
how would I use regex to match a word, let's say "the" but only if it's not part of a link in any shape or form so
<a href="NOT IF IT'S IN HERE">AND NOT IF IT'S IN HERE</a>
DonWilson
I'd suggest looking for <a >...</a> and replacing that whole thing with a blank statement, instead of trying to find the text out side of it.
Trel
no you don't understand, look at the example below

I have the following html

CODE
<a href="www.thesite.com">the best site</a>  Click the link


now I want it to match the word "the" in "click the link" but not in the "thesite.com" or "the best site"

that's what I'm trying to do.
primetime
You could try doing:
CODE
<?php
-- fubared ---
?>


GAH.... IPB is breaking the code...

OOoo..k...

Well let's try this.. since IPB is breaking it..
CODE
</a>(.+|040|)(the)(040|.+|<|)
primetime
Hmm.. ok.. I guess not.. just escape the / of the </a> in my post above and if you're using preg_match("/".$postabove."/i", $linetoberegexed, $match); it's $match[2];
Trel
That doesn't look like it'd work though because what if I had a "the" before the closing of the first <a>, that one would not be matched
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.