Posted by Chung Leong on 11/23/05 04:36
Tomek Toczyski wrote:
> I would like find all occurences of "ABC" which are not followed by "123"
> and replace them with "abc". For example:
> "ABC dd" -> "abc dd"
> "ABC123" -> "ABC123"
> "ABC 123" -> "abc 123"
>
> Give me a recipe, please. I've spent 2 hours googling for it.
>
>
> -tt.
preg_replace_callback() is your friend. Use preg_replace_callback().
Example:
function lowercase_callback($m) {
return strtolower($m[0]);
}
$s = preg_replace_callback('/[A-Z]+(?![A-Z\d])/', 'lowercase_callback',
$s);
Navigation:
[Reply to this message]
|