You dont need to use regex, you can use two replace to solve your problem :
String replace = convert.replace("1", "one ").replace("0", "zero ");
Example :
int i = 55;
System.out.println(Integer.toBinaryString(i));
System.out.println(Integer.toBinaryString(i).replace("1", "one ").replace("0", "zero "));
Output
110111
one one zero one one one
Edit after more than one year.
As @Soheil Pourbafrani ask in comment, is that possible to traverse the string only one time, yes you can, but you need to use a loop like so :
before Java 8
int i = 55;
char[] zerosOnes = Integer.toBinaryString(i).toCharArray();
String result = "";
for (char c : zerosOnes) {
if (c == '1') {
result += "one ";
} else {
result += "zero ";
}
}
System.out.println(result);
=>one one two one one one
Java 8+
Or more easier if you are using Java 8+ you can use :
int i = 55;
String result = Integer.toBinaryString(i).chars()
.mapToObj(c -> (char) c == '1' ? "one" : "two")
.collect(Collectors.joining(" "));
=>one one two one one one
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…