Re: trying to match the front and end...

From: Date: Fri, 08 Aug 2003 16:48:12 +0000
Subject: Re: trying to match the front and end...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-158892@lists.php.net to get a copy of this message
Dan Joseph wrote:
From John:
$new_number = preg_replace('/^'.$this->start_num.'([0-9]+)'.$this->end_num.'$/',
'\\1',$old _number); The one that Mike gave didn't seem to do anything, John's will work if it can match the beginning and the end successfully. I should probably explain myself further. Sometimes there won't be anything to replace at the front, and sometimes nothing at the end. So it'd still need to do the front and/or end wether or not they both exist. Is there a way to tweak these to do that?
Should be: $new_number = preg_replace( '/^('.$this->start_num.')?([0-9]+)('.$this->end_num.')?$/', '\\2', $old _number); -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ PHP|Architect: A magazine for PHP Professionals – www.phparch.com

« previous php.general (#158892) next »