Tuesday, May 26, 2015

Brazillian phone format with Java


String num = "11936247832";
Pattern pattern = new Pattern("(\\d{2,2})(\\d{4,5})(\\d{4,4})");
Matcher res = pattern.matcher(num);
if (res.find()) {
   System.out.println("("+res.group(1)+") "+res.group(2)+"-"+res.group(3));
}

No comments:

Post a Comment