Is there any way I can format a string into a specific pattern using regex or is stringbuilder + substring a faster approach?
For example, say a phone number --> 123
StringBuilder with substring will be faster, but not always the simplest/best approach. In this case I would just use substring.
String num = "1234567890"; String formatted = "(" + num.substring(0,3) + ") " + num.substring(3,6) + "-" + num.substring(6);