import java.util.regex.Matcher;/*来自 n o w j a v a . c o m - 时 代 Java*/
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
String regex = "\\b(\\d{3})(\\d{3})(\\d{4})\\b";
String replacementText = "($1) $2-$3";
String source = "1111111111, 1111111, and 1111111111";
// Compile the regular expression
Pattern p = Pattern.compile(regex);
// Get Matcher object
Matcher m = p.matcher(source);
/** from
N o w J a v a . c o m - 时代Java**/
// Replace the phone numbers by formatted phone numbers
String formattedSource = m.replaceAll(replacementText);
/**代码未完, 请加载全部代码(NowJava.com).**/
本文系作者在时代Java发表,未经许可,不得转载。如有侵权,请联系nowjava@qq.com删除。