Re: Regular Expression Query

From: Date: Sat, 06 Jan 2001 18:53:14 +0000
Subject: Re: Regular Expression Query
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-33043@lists.php.net to get a copy of this message
> I think the most difficult thing I've encountered so far in trying to > learn PHP, as a novice programmer, is regular expressions. > > I'm trying to use ereg_replace on a string containing a large quantity > of data taken from a webpage which I then parse using > the explode function. > > One regularly occuring string is: (Reference #xxx) > > Where xxx is a number of up to 3 digits. > > I want to replace this string using back references to just xxx > and I've tried using the following: > > $out = ereg_replace("\(Reference #.([0-9]+).\)","\\1",$in); > > I just can't suss why this doesn't work. > > Any pointers anyone? What are those .'s for in your regex? Just make it: "\(Reference #([0-9]+)\)" and I bet it will work. with the .'s there you would only get the middle digit of your xxx -Rasmus

« previous php.general (#33043) next »