Re: problems with regex

From: Date: Sat, 27 May 2006 14:19:18 +0000
Subject: Re: problems with regex
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-237006@lists.php.net to get a copy of this message
Merlin wrote:
Hi there, I am somehow lost when it comes to regex. I am trying to remove ! and ? characters from a string. Could somebody please help me to get a working regex running for that? I tried: $str = preg_replace('/\!\?\./', ' ', $str);
$s = "?!help!?"; echo "--",$s,"--",preg_replace("#[\\!\\?]#", "", $s),"--\n"; notice I use double quotes (because it means I can test the code on the command line) and therefore I'm escaping the backslashes. basically you need to add the square brackets around the chars in question in order to say 'any one of these chars'.... <quote from="http://php.net/manual/en/reference.pcre.pattern.syntax.php">
[
    start character class definition
]
    end character class definition
</quote>
Thank you for any help, Merlin


« previous php.general (#237006) next »