javascript - Format numeric string -
i've following string (meaning it's not numeric):
"0870490055012000000000"
wich 22 characters long. need transform into:
"087.049.0055.0120.0000.0000"
using php or on js/client side.
i found this not able solve problem.
i guess there many ways solve this. i'm asking like:
$x= format("00000", "xxx.xxx..xxx.x.x.x")
or
$x = preg_replace("/a;;w.;w;e;ew")
with php, can use this:
$str = preg_replace('~\a\d{3}\k\d{3}|\d{4}~', '.$0', $str);
where \a
anchor start of string.
\k
removes have been matched on left match result.
if need more general apply mask string, link shared in question give way do.
Comments
Post a Comment