提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
\(代表左括号,而\)代表右括号。
/*from 时 代 J a v a*/ import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static void main(String[] args) { Pattern pattern = Pattern.compile("\\(\\d{3}\\) \\d{3}-\\d{4}"); Matcher matcher = pattern.matcher("(779) 148-1212"); if (matcher.matches()) System.out.println("Match."); else System.out.println("Does not match."); } }