将正则表达式BBcode模式转换为HTML正则表达式

时间:2014-08-22 06:11:44

标签: html regex bbcode

我正在研究小项目并坚持使用bbcode模式正则表达式转换为html模式正则表达式。

目前使用[pre] [/pre] BBcode工作的代码;我想编写HTML正则表达式代码:

$pattern = '#\[pre\](.*?)\[\/pre\]#si';

$pattern = '#\[.?pre\]#si'; 

我尝试将其转换为如下所示,但它不起作用(没有得到预期结果):

$pattern = '#\<pre\>(.*?)\<\/pre\>#si';

$pattern = '#\<.?pre\>#si';

1 个答案:

答案 0 :(得分:1)

我不确定你是如何使用正则表达式的,但以下内容对我有用:

<?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"
?>
相关问题