【发布时间】:2026-01-13 16:50:01
【问题描述】:
我需要为我在 PHP 中的语法高亮脚本做一个简单的正则表达式查找和替换。
我需要一串代码,它实际上是一个完整的 php 文件,被读入这样的字符串。
$code_string = 'the whole source code of a php file will be held in this string';
然后找到这些的所有出现并进行替换...
查找:[php] 并替换为 <pre class="brush: php;">
查找:[/php] 并替换为 </pre>
找到 [javascript] 并替换为 <pre class="brush: js;">
查找:[/javascript] 并替换为 </pre>
我真的不擅长正则表达式,有人可以帮我解决这个问题吗?
【问题讨论】:
-
奇怪的类名是怎么回事?
-
@thephpdeveloper:一些 JS 插件使用这种奇怪的类来指定参数,尽管它们通常在相关类中的任何地方都不需要空格(即
unrelatedclass brush:js;而不是unrelatedclass brush: js;)。