java - Regex to add digit between delimiter characters if missing -
i didn't use regex lot , need little bit of help. have situation have digits separated dot char, this:
0.0.1 1.1.12.1 20.3.4.00.1
now ensure each number between .
has 2 digits:
00.00.01 01.01.12.01 20.03.04.00.01
how can accomplish that? thank help.
you can use string.split()
accomplish this:
public static void main(string[] args) { string[] splitstring = "20.3.4.00.1".split("\\."); string output = ""; for(string : splitstring) { if(a.length() < 2) { = "0" + a; } output += + "."; } output = output.substring(0, output.length() - 1); system.out.println(output); }
Comments
Post a Comment