Compiling a Pattern with Multiple Flags - Java Regular Expressions

Java examples for Regular Expressions:Pattern

Description

Compiling a Pattern with Multiple Flags

Demo Code

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
  public static void main(String[] args) {
    CharSequence inputStr = "Abc\ndef";
    String patternStr = "abc$";

    // Compile with multiline and case-insensitive enabled
    Pattern pattern = Pattern.compile(patternStr, Pattern.MULTILINE
        | Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(inputStr);
    boolean matchFound = matcher.find(); // true
  }/*from   w  w w. ja v a2s .  c o m*/
}

Related Tutorials