Re: (another) regex difficulty
| From: | Cristian Lavaque | Date: | Wed, 01 Oct 2003 23:37:23 +0000 |
| Subject: | Re: (another) regex difficulty | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-164641@lists.php.net to get a copy of this message | ||
Cristian Lavaque wrote:
> 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
doh, I now understand your question, you don't mean the asterisk literally,
but as any character that follows a backslash... sorry -_-
In a character class, you can negate that class by starting it with ^, but
how do you negate something that's not a class? in this case "\\.", cause if
it's in a charactar class, it'll match "\n" or "n\\\\\\". Is there a
simple
way to negate a string with regular expression? I hope I wasn't too
confusing in my question.
Cristian