Re: Unexplained Issue Using Regex

From: Date: Sat, 07 Mar 2009 12:10:16 +0000
Subject: Re: Unexplained Issue Using Regex
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-289533@lists.php.net to get a copy of this message
On Fri, 6 Mar 2009 21:32:53 +0200, Nitsan Bin-Nun wrote: > Hi lista, > > I have been trying to figure this out for the last couple of hours but I'm > lack of luck. > Take a look at these regex's, the string that was inputed into the > preg_replace (using Uis modificators) and the results: > (the lists have correspondence to each other) > > ORIGINAL STRING > ---- > http://www.zshare.net/video/541070871c7a8d9c > > REGEX USED (with Uis modificators) > ---- > http:\/\/(www\.|)zshare\.net\/video\/([^\/]+) $3 > > THE RETURNED STRING > ---- > 41070871c7a8d9c Is this what you're doing? echo preg_replace('/http:\/\/(www\.|)zshare\.net\/video\/([^\/]+)/Uis', '', 'http://www.zshare.net/video/541070871c7a8d9c'); echo "\n"; The "U" modifier turns the plus ungreedy so that it matches only the first character. And what's the "$3" about? Are you doing this? echo preg_replace('/http:\/\/(www\.|)zshare\.net\/video\/([^\/]+)/Uis', '$3', 'http://www.zshare.net/video/541070871c7a8d9c'); echo "\n"; I think someone mentioned that the index "$3" doesn't exist. If you change it to "$2" you would get the correct result because "$2" mathces "5" and the rest ("41070871c7a8d9c") remains unreplaced. At least that's what I think is going on... /Nisse

« previous php.general (#289533) next »