RE: [PHP] Have part not be replaced in regex?
| From: | John W. Holmes | Date: | Tue, 29 Oct 2002 00:27:32 +0000 |
| Subject: | RE: [PHP] Have part not be replaced in regex? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-121798@lists.php.net to get a copy of this message | ||
> I'm using some regexes for swear filtering, but I have a problem. I
> need to look for ab[ct] and have it replaced by xyz but not replace
the
> [ct]. I.e. it would be replaced by xyzc or xyzt. Any ideas?
$new_string = preg_replace("/ab([ct])/","xyz\\0",$old_string);
or
$new_string = ereg_replace("ab([ct])","xyz\\1",$old_string);
preg_replace is generally faster.
---John Holmes...