简体   繁体   中英

php regex strange error

i use such regex $msg = preg_replace('/<b>(\\w)<\\/b>/', '9999', $msg); to replace <b>test</b> but it not replace. why?

You're missing the quantity token. That would only match one character long strings between the <b> tags.

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

尝试这个

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

Your \\w does not match. I don't find my regex manual right now, but use something like .* .

注意\\ w +之后的加号

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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