Jump to content

Match all apperances of a word but not inside html tags


AudiS2

Recommended Posts

Hi gang,

 

I need a regexp that will match my target word inside a text but not contained within any html tags.

 

For example if the word is "cars"

and text is:

 

I love cars  <a href="cars">cars</a>

 

I want to match first but not the other two.  Possible?

 

 

Were you mistaken in your description of your expected match? Because the 3rd 'cars' isn't really inside html tags, it is simply surrounded by them, as is everything else that is not "in an html tag" in an html document. I'd think you really mean to not match just the 2nd occurrence of 'cars'. If so, look at this thread:

http://www.phpfreaks.com/forums/index.php/topic,122857.0.html

 

Also see this pattern:

http://nancywalshee03.freehostia.com/regextester/regex_tester.php?seeSaved=uo23fkfh

Ok dsaba, good point. Let me explain it in more detail.

 

In my particular case I need not to match a word that is a part of a link (<a>) but for other tags (<p>cars</p>) it should match them.

 

Thing is I will be replacing the word with a link, and I do not want to do that for words that are already a part of a link (or html tag). I hope it is now more clear what I try to achieve.

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.