2017-08-30 254 views
0

這裏是我的字符串:正則表達式的表達,去除<div class...</div>

"<img width="300" src="https://www.dvrgv.org/PhotosArticles/2017-07-25-VeloTaxi.jpg" alt="Manu dans le vélo-taxi, Brigitte aux commandes" /><br /> 
    <P>En juillet 2017, </P> 
    <div class="powerpress_player" id="powerpress_player_9779"><!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]--> 
    <audio class="wp-audio-shortcode" id="audio-1097-1" preload="none" style="width: 100%;" controls="controls"><source type="audio/mpeg" src="https://www.dvrgv.org/_Reportages/2017-07-26-BrigiteVeloTaxi.mp3?_=1" /><a href="https://www.dvrgv.org/_Reportages/2017-07-26-BrigiteVeloTaxi.mp3">https://www.dvrgv.org/_Reportages/2017-07-26-BrigiteVeloTaxi.mp3</a></audio></div>dddf" 

我正在尋找一個正則表達式,我的目標:

"<img width="300" src="https://www.dvrgv.org/PhotosArticles/2017-07-25-VeloTaxi.jpg" alt="Manu dans le vélo-taxi, Brigitte aux commandes" /><br /> 
    <P>En juillet 2017, </P>dddf" 

如果有人能幫助

回答

0

更嚴格,不容易出錯的正則表達式比abskmj的答案如下:(?,而不是*。*)

preg_replace("/(.*?)<div class=\".*?\/div>(.*)/s","$1$2",$your_text); 

其採用了非貪婪修改。如果您使用貪婪修飾符*。在你的文本中有一個關閉div標籤bellow dddf的例子,然後正則表達式將取代所有內容,直到最後一個關閉div找到你可能不想要的東西。

0

我找到了解決辦法;-)

我必須管理符合[\s\S]突破!

​​