import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {/**来 自 n o w j a v a . c o m**/
public static void main(String[] args) {
// Prepare the regular expression
String regex =
"\\b(?<areaCode>\\d{3})(?<prefix>\\d{3})(?<lineNumber>\\d{4})\\b";
// Reference first two groups by names and the thrd oen as its number
String replacementText = "(${areaCode}) ${prefix}-$3";
String source = "1111111111, 1111111, and 1111111111";
// Compile the regular expression
Pattern p = Pattern.compile(regex);
// Get Matcher object
Matcher m = p.matcher(source);
// Replace the phone numbers by formatted phone numbers
/**
来 自 时 代 J a v a 公 众 号
**/
/**代码未完, 请加载全部代码(NowJava.com).**/
本文系作者在时代Java发表,未经许可,不得转载。如有侵权,请联系nowjava@qq.com删除。