preg_replace and preg_match in one call

From: Date: Sun, 16 Jul 2000 23:10:19 +0000
Subject: preg_replace and preg_match in one call
Groups: php.general 
Request: Send a blank email to php-general+get-6854@lists.php.net to get a copy of this message
Hi, assume the following call: $str = "test[1]"; $str = preg_replace("/\[(\d+)\]$/", "", $str); Now I have the string replaced, but how do I access the value remembered by the (\d+), which here would be 1? Right not I am using preg_replace and preg_match do accomplish this. But I think it would be nice to basically pass an optional 3rd parameter to preg_replace where all the matches would be stored. $str = "test[1]"; $str = preg_replace("/\[(\d+)\]$/", "", $str, $matches); // $matches[1] would contain 1 Thanks, BTW: I might be totaly off here, as I am not very familiar with all the PREG stuff. Florian Clever USA 503 977-0480 (Office) USA 503 246-2803 (home) http://www.Clever-Software-Solutions.de

« previous php.general (#6854) next »