Format phone number String input = "1234567890"; String number = input.replaceFirst("(d{3})(d{3})(d+)", "($1) $2-$3"); System.out.println(number);