Re: Regular expressions

From: Date: Fri, 24 Oct 2003 16:09:41 +0000
Subject: Re: Regular expressions
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-167493@lists.php.net to get a copy of this message
Fernando Melo wrote: > I have the following statement: > > $text = ereg_replace > ("[live/]*content\.php\?[&]*Item_ID=([0-9]*)&Start=([0-9]*)&Category_ID=([0- > 9]*)[&]*", "content\\1start\\2CID\\3.php", $text); > > Basically what I'm trying to do is if the URL includes "live/" then I want > to include it in the replace. The way I have it now check for all the > letters in "live" instead of the whole string. > > I hope I explained this properly. $text = ereg_replace ("(live/)?content\.php\?[&]*Item_ID=([0-9]*)&Start=([0-9]*)&Category_ID=([0-9]*)[&]*", "content\\1start\\2CID\\3.php", $text); The "(live/)?" should catch zero or one occurence of "live/". Maybe the regex library in your PHP doesn't know about "?", than you could use "*" instead - consider using the PCRE preg_replace function. Regards... Michael

« previous php.general (#167493) next »