Java examples for Regular Expressions:Pattern
Duplicating elements rather than using a quantifier \d\d is \d{2}
import java.util.regex.Matcher; import java.util.regex.Pattern; 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/*from w ww . j a va2 s .c o m*/ System.out.println("Does not match."); } }