I am using the following pattern with preg_replace to remove unwanted characters
Code: Select all
#[^-a-zA-Z0-9+_.,!*()$]#Can someone tell me what I am doing wrong please ?
Any help would be much appriciated.
Thanks,
Brew
Moderator: General Moderators
Code: Select all
#[^-a-zA-Z0-9+_.,!*()$]#Code: Select all
#[^-a-zA-Z0-9_.,!*()$]#Code: Select all
#[^-a-zA-Z0-9_.,!*()$]+#So you want to keep the plus signs and A-Z etc?Brew wrote: I am using the following pattern with preg_replace to remove unwanted characters
I don't get it... How does removing + from the negated character class solve that problem?GeertDD wrote:The + metacharacter (and most other metacharacters) lose their special meaning inside a character class. So don't put it in there and it's fixed.
That is not possible. The regex you posted will NOT remove the '+'-s from your string.Brew wrote:Hi
I am using the following pattern with preg_replace to remove unwanted characters
This works perfectly apart from it removes the plus sign (+) from a string, even though I have specified it in the pattern.Code: Select all
#[^-a-zA-Z0-9+_.,!*()$]#
...
Code: Select all
echo preg_replace('#[^-a-zA-Z0-9+_.,!*()$]#', '', '#+%');