php - Replace all dot only in string, but not in numeric values -
i want replace occurrence of dot (.) in string not digits or numeric value. have given example
string : 10.10.2015 11.30 09/2007 83 hello.how.are.you $.### output : 10.10.2015 11.30 09/2007 83 hello how $ ###
i tried using preg_replace in php
use non-capturing lookbehind group test if previous character digit or not
$string = '10.10.2015 11.30 09/2007 83 hello.how.are.you $.###'; $result = preg_replace('/(?<=[^\d])\./', ' ', $string); var_dump($result);
explanation
(?<=[^\d])\. -------- -- ^ ^ | | | ------------------ escape `.` we're working literal | dot rather "any character" | ----------------------- preceding non-digit character don't include in replace group
Comments
Post a Comment