Page 1 of 1

Replace 4, but not 40

Posted: Mon Jul 25, 2005 6:13 am
by tores
Hi

How can I modify the following regexp

Code: Select all

echo preg_replace("/,4(,|)/", ",S", "40,4,40,4"); // Outputs 40,S40,S
so it outputs "40,S,40,S".

regards tores

Posted: Tue Jul 26, 2005 5:26 am
by anjanesh

Code: Select all

echo preg_replace("/(^|,)(4)(,|$)/", "\$1S\$3", "40,4,40,4"); // outputs 40,S,40,S