Re: problems with regex

From: Date: Tue, 30 May 2006 02:33:18 +0000
Subject: Re: problems with regex
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-237057@lists.php.net to get a copy of this message
On Sat, May 27, 2006 8:58 am, Merlin wrote: > 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); An alternative: $str = preg_replace('/[\\!\\?\\.]*/', ' ', $str); And usual rant #37: \ and ' are special characters inside of '' and you really SHOULD escape them, even though PHP will let you get away with not doing it, yea, even unto it being a "documented feature" that \x will turn into \x so long as x is not \ or ' I also think str_replace() might be more appropriate, but would be cautious about claims on speed for str_replace versus preg_replace, if, for example, the array() of characters to be replaced was HUGE... You'll have to benchmark on your own gear *IF* it matters to you, which I doubt. -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#237057) next »