Create more than one range in a class - Java Regular Expressions

Java examples for Regular Expressions:Pattern

Introduction

The first character can be lowercase a through zor uppercase A through Z.

Demo Code

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.");
  }

}

Related Tutorials