Java examples for Regular Expressions:Pattern
The first character can be lowercase a through zor uppercase A through Z.
import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static void main(String[] args) { Pattern pattern = Pattern.compile("[a-zA-Z][0-5]"); Matcher matcher = pattern.matcher("r2"); if (matcher.matches()) System.out.println("Match."); else/* w w w . j av a2 s .c om*/ System.out.println("Does not match."); } }