正则表达式 - 删除<pre> tag

时间:2017-10-23 20:47:05

标签: php regex

I have html code and I want to remove all code inside "pre" tag using regular expression

For example

<pre>lorem ipsum</pre>
<p><strong>lorem ipsum</p>
<pre>lorem ipsum</pre>

and I want to get only

<p><strong>lorem ipsum</p>

I try this:

<pre>.*?</pre>

but it doesn't work

1 个答案:

答案 0 :(得分:0)

一个简单的有趣的Javascript清洁前:

&#13;
&#13;
var pres = document.querySelectorAll('pre');
for(var i in pres){
  pres[i].textContent = "";
}
&#13;
pre{
 text-align: center;
 background-color: #cccccc;
 border-radius: 8px;
 width:100%;
 height:50px;
}
&#13;
<pre>lorem ipsum</pre>
<p><strong>lorem ipsum</p>
<pre>lorem ipsum</pre>
&#13;
&#13;
&#13;