提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
复制元素而不使用量词\ d \ d是\ d {2}
import java.util.regex.Matcher; import java.util.regex.Pattern;/** from n o w j a v a . c o m - 时代Java**/ public class Main { public static void main(String[] args) { Pattern pattern = Pattern.compile("\\d{2}-\\d\\d"); Matcher matcher = pattern.matcher("12-12"); if (matcher.matches()) System.out.println("Match."); else System.out.println("Does not match."); } }