Updated working code
public String stringExpansionRegEx(String str) {
StringBuilder result = new StringBuilder();
boolean bool = Pattern.matches("([a-zA-Z]\\d)+", str);
if (bool == true){
for (int i=0;i<str.length();i+=2) {
char ch = str.charAt(i);
int count = Integer.parseInt(String.valueOf(str.charAt(i+1)));
for (int j = 0; j < count; j++) {
result.append(ch);
}
}
}
return result.toString();
}