Using custom character classes - Java Regular Expressions

Java examples for Regular Expressions:Pattern

Introduction

List all the characters that you want included in the class within a set of brackets.

For example:

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("b[aeiou]t");
    Matcher matcher = pattern.matcher("bet");
    if (matcher.matches())
      System.out.println("Match.");
    else/*from w ww  .java 2 s  .com*/
      System.out.println("Does not match.");
  }
}

Related Tutorials