简体   繁体   English

PHP正则表达式奇怪的错误

[英]php regex strange error

i use such regex $msg = preg_replace('/<b>(\\w)<\\/b>/', '9999', $msg); 我使用这样的正则表达式$msg = preg_replace('/<b>(\\w)<\\/b>/', '9999', $msg); to replace <b>test</b> but it not replace. 替换<b>test</b>但不能替换。 why? 为什么?

You're missing the quantity token. 您缺少数量令牌。 That would only match one character long strings between the <b> tags. 那只会在<b>标记之间匹配一个字符长的字符串。

$msg = preg_replace('/<b>(\w*)<\/b>/', '9999', $msg); 

尝试这个

$msg = preg_replace('#<b>(\w)*<\/b>#', '9999', $msg);

Your \\w does not match. 您的\\w不匹配。 I don't find my regex manual right now, but use something like .* . 我现在找不到我的正则表达式手册,但是使用类似.*东西。

注意\\ w +之后的加号

 $msg = preg_replace('/<b>(\w+)<\/b>/', '9999', $msg);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM