Goal: prefix each number in a string with 1-5 zeros depending on the number
e.g. if it's less than 10 then prepend 4 zeros, if it's two digits then prefix three zeros.
This basically prefixes each number with zeros so each number is 5 digits.
String str = "1 - test 86";
String str = "00001 - test 00086";
I've tried this but this adds zeros to every number
str = str .replaceAll("(\\d+)", "00000$1");
Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.