我正在尝试执行此正则表达式匹配和替换,但无法执行。
例子
<SPAN class="one">first content here</SPAN>
<SPAN class="two">second content here </SPAN>
<SPAN class="three">one; two; three; and more.</span>
<SPAN class="four">more content here.</span>
我想找到每组 span 标签并用这样的东西替换
查找
<SPAN class="one">first content here</SPAN>
更改为
<one>first content here</one>
与其余的 span 标签相同。
class="one"
, class="two"
等等是我在正则表达式匹配表达式中使用的唯一关键标识符。因此,如果我找到具有这些类的 span 标记,那么我想进行替换。我的主要问题是我无法找到第一个结束标记的出现,所以它所做的是从头到尾找到没有用的东西。到目前为止,我一直在尝试使用 notepad++ 来执行此操作,但发现它有其局限性,因此将不胜感激任何 php 帮助。
问候
最佳答案
preg_replace('/<span class="(.*?)">(.*?)<\/span>/i', '<$1>$2</$1>', $input);
关于PHP 正则表达式 - 查找和替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2594051/