php - Finding position of last digit in string -
i'm trying format number plates - need find last digit in string , add space after it, e.g.
t4max = t4 max t53tes = t53 tes
i'm assuming i'll have use preg_replace - i've tried below find position in string of last digit, returns empty array.
preg_match('/(0-9])/', $plate, $matches, preg_offset_capture);
any ideas?
that's easy:
$str = 't4max'; $str_with_space = preg_replace('~\d(?=\d*$)~', '$0 ', $str);
online demo: http://ideone.com/mqqqsh
regex explanation:
~\d(?=\d*$)~
expression means - digit \d
followed not digit \d
end of string.
Comments
Post a Comment