Dusan Plavak
Dusan Plavak

Reputation: 4579

regex exclude nested html tag

i have a piece of text:

<strong>blalblalba</strong>blasldasdsadasdasd<strong> 3.5m Euros<br>
<span class="style6">SOLD</span></strong>

and I want to remove <strong> contains $|euros|Euros</strong>

So far I have:

preg_replace('#<strong>.*?(^<strong>).*?(\$|euros|Euros|EUROS).*?</strong>#is', '', $result);

but it is not working... I was trying also negative lock head (?!) but still not working...

Any help? Thanks

Upvotes: 0

Views: 216

Answers (2)

user557597
user557597

Reputation:

You can try this, must use 'Dot-All' modifier or substitute [\S\s] -

 # <strong>(?:(?!\1)(?:\$|euros|Euros|EUROS)()|(?!<strong>).)+</strong>\1

 <strong>
 (?:
      (?! \1 )
      (?: \$ | euros | Euros | EUROS )
      ( )
   |  
      (?! <strong> )
      . 
 )+
 </strong>
 \1 

Upvotes: 1

Joe T
Joe T

Reputation: 2350

With the assumption you expect two stong's before your Euros, I think this may be what you want: preg_replace('#^<strong>.*?<strong>.*?(\$[euros|Euros|EUROS]).*?</strong>#is', '', $result);

Upvotes: 1

Related Questions