What does \d\W[a-z] mean in regular expression - Java Regular Expressions

Java examples for Regular Expressions:Pattern

Introduction

\d\W[a-z] requires a digit in the first position, a white space character in the second position, and one of the letters a through z in the third position.

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("\\d\\W[a-z]");
    Matcher matcher = pattern.matcher("1 a");
    if (matcher.matches())
      System.out.println("Match.");
    else//from  w  w  w. j a  va2 s  .c o  m
      System.out.println("Does not match.");
  }

}

Related Tutorials