我正在做一个小项目,坚持用bbcode模式regex转换成html模式regex。
目前使用[pre] [/pre]
BBcode代码工作;我想编码工作HTML正则表达式:
$pattern = '#[pre](.*?)[/pre]#si';
$pattern = '#[.?pre]#si';
我尝试转换它如下,但它不工作(没有得到预期的结果):
$pattern = '#<pre>(.*?)</pre>#si';
$pattern = '#<.?pre>#si';
我不知道你是如何使用正则表达式,但以下工作对我来说:
<?php
$text = "<pre>regex use check inside pre tag conetent</pre>";
$found = preg_match( '#<pre>(.*?)</pre>#si', $text, $matches);
echo $matches[1]; // prints: "regex use check inside pre tag conetent"
?>