Reputation: 14614
i use such regex $msg = preg_replace('/<b>(\w)<\/b>/', '9999', $msg);
to replace <b>test</b>
but it not replace. why?
Upvotes: 1
Views: 68
Reputation: 1416
Notice the plus after \w+
$msg = preg_replace('/<b>(\w+)<\/b>/', '9999', $msg);
Upvotes: 0
Reputation: 3701
Your \w
does not match. I don't find my regex manual right now, but use something like .*
.
Upvotes: 0
Reputation: 15735
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);
Upvotes: 5