RE: [PHP] Advanced RegExp

From: Date: Fri, 20 Oct 2000 13:45:08 +0000
Subject: RE: [PHP] Advanced RegExp
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-21384@lists.php.net to get a copy of this message
Hi Mukul, > I was wondering what > > \\1 ... \\2 meant in ereg... > > and how to occurenece in a string... I'll just give you an example and I think you'll understand. <? $test = "Mukul 123"; $test = eregi_replace("^([a-z]+) ([0-9])$","Hello \\1 this is number \\2<br>\n", $test); // ^ \\1 ^ ^ \\2 ^ print $test; ?> So \\1 contains the first part of the result which is surrounded by (), \\2 the second and so on... you just count the opening paranthesis from left to right. There's one limitation though you have with ereg_*-functions you can only count till nine. Hope this helps. Cheers, Matthias

« previous php.general (#21384) next »