I found this regex that works great if there are no alphabets in the provided string.
$string = "12522191813381147500333332228323"; echo $formattedString = preg_replace("/^(\d{8})(\d{4})(\d{4})(\d{4})(\d{12})$/", "$1-$2-$3-$4-$5", $string);
My input line will someday be a combination of alphabets and numbers. What changes should I make to make it work in both cases. I have another alternative to iterating over a string and adding dashes using PHP string functions, but I want to find out how we can achieve this using a regular expression.
source share