fork download
  1. class Solution {
  2. public static void main(String[] args) {
  3. String s = "00-44 48 5555 8361";
  4. System.out.println(solution(s));
  5. String s2 = "00-44 48 5555 8361 xxx 1";
  6. System.out.println(solution(s2));
  7. String s3 = "12345";
  8. System.out.println(solution(s3));
  9. }
  10.  
  11. public static String solution(String s) {
  12. return s.replaceAll("[^\\d]", "").replaceAll("...", "$0-").replaceAll("-$", "");
  13. }
  14. }
Success #stdin #stdout 0.04s 2184192KB
stdin
Standard input is empty
stdout
004-448-555-583-61
004-448-555-583-611
123-45