Re: (another) regex difficulty
| From: | Cristian Lavaque | Date: | Wed, 01 Oct 2003 20:36:23 +0000 |
| Subject: | Re: (another) regex difficulty | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-164610@lists.php.net to get a copy of this message | ||
Jonas_weber @ Gmx . Ch wrote:
> regular expressions
> the example below should turn any character exept "\*" (*= any char)
> into an "x":
>
> $term = preg_replace('/[^(\\\)+(.){1}]/', 'x', $term);
>
> but i guess because of the [brackets] the "." (period) is treated as
> character "." instead as metacharacter (that matches any char).
I'm new to regex too, but if you want to match anything that's not an *,
couldn't it be done like this?
$term = preg_replace('/[^\*\s]*/', 'x', $term);
I put the \s there to skip the whitespace characters too. I haven't tested,
but I hope it helps.
Cristian