0

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

Dusan Plavak
  • 4,457
  • 4
  • 24
  • 35
  • 2
    A regex is too difficult for this/you. Try one of the [simpler alternatives](http://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php). – mario Sep 16 '13 at 23:26
  • A little more specific in what you're trying to remove would help. –  Sep 16 '13 at 23:29
  • I'm curious the intention of the ^ here `'#.*?(^` since I believe that indicates "beginning of the string" and will cause this to never match. – Joe T Sep 16 '13 at 23:29
  • well ^ also can mean not include? sorry I edited question :D coz was missinterpreted – Dusan Plavak Sep 16 '13 at 23:32
  • 4
    afaik ^ means "not include" only when inside [square brackets] not (parens) – Joe T Sep 16 '13 at 23:35

2 Answers2

1

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);

Joe T
  • 2,300
  • 1
  • 19
  • 31
  • then try this `preg_replace('#.*(.*?\$[euros|Euros|EUROS].*?)#is', '', $result);` – Joe T Sep 16 '13 at 23:41
  • this works on my server for your input string (removed $ since not in your example) `preg_replace('#.*(.*[euros|Euros|EUROS].*?)#is', '', $result);` – Joe T Sep 16 '13 at 23:54
  • not working at all please, this can not work because you have euros in []... so it means that it will match letters, also your approach is not good because .* will replace also characters outside nested element – Dusan Plavak Sep 17 '13 at 00:00
  • nope only what is inside inner parens gets replaces, as i said it works on my server with your example, and you are giving contradictory requests as to what you're attempting. i suspect mario's comment above is correct. – Joe T Sep 17 '13 at 00:21
1

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