I am trying to figure out that -
INPUT: String data = "506313B5EA3E";
OUTPUT: String data = "50:63:13:B5:EA:3E";
I tried using-
java.util.Arrays.toString(data.split("(?<=\\G..)"))
But the output is: [50, 6313B5EA3E]
You can use a RegExp:
String input = "0123456789abcdef";
String output = input.replaceAll("..(?!$)", "$0:")
// output = "01:23:45:67:89:ab:cd:ef"
How does it work?
..
matches exactly two characters. (?!$)
ensures that these two characters are not at the end of input
(?!
is a negative lookahead, $
stands for the end). $0
means the whole matching string) and the colon we want.replaceALL
, this operation repeats for every two-character group. Remember: except the last one.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With