且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

替换php中的完全匹配

更新时间:2023-02-22 08:50:49

这在很大程度上取决于您的数据在 $r_val 中的格式,但一个好的起点是尝试:>

This depends alot on how your data is formatted inside $r_val, but a good place to start would be to try:

$r_val = preg_replace('/(?<!\.)\b0\b(?!\.)/', '-', $r_val);

其中 \b 是一个长度为 0 的字符,表示单词"的开头或结尾.

Where \b is a 0-length character representing the start or end of a 'word'.

听起来很奇怪,但 Perl regex 文档 实际上非常适合解释preg_* 函数的正则表达式部分,因为 Perl 是实际实现功能的地方.

Strange as it may sound, but the Perl regex documentation is actually really good for explaining the regex part of the preg_* functions, since Perl is where the functionality is actually implemented.