I have a string "48a493d902b5", but I need to convert it in "48:a4:93:d9:02:b5". I could build a While structure but i don’t know if it is the better aproach.
Is it possible use Regex for it? If so, How can I do it?
>Solution :
Yes, it’s possible use a regex. This expression (.{2}) splits the String in pairs of characters using the lookBehind (?<=\G.{2}) and in the sequence inserts ":" between this pairs, except for the last pair (?!$).
String originalString = "48a493d902b5";
String formatedString = originalString.replaceAll("(?<=\\G.{2})(?!$)", ":");
System.out.println(formatedString);