0

How do I ignore case for my match? I am trying to match:

public static void main(String[] args) {
    Pattern pattern = Pattern.compile("(?i)^concat\\(",Pattern.MULTILINE);
    Matcher matcher = pattern.matcher("CONCAT(trade,ca)");
    System.out.println(matcher.find());
}

Possible scenarios

CONCAT( = true
concat( = true
CONCAT(test = true
concat(test = true
concat = false
CONCAT = false
TESTCONCAT( = false
Mark Rotteveel
  • 90,369
  • 161
  • 124
  • 175
Jigar Naik
  • 1,666
  • 5
  • 24
  • 55

1 Answers1

2

Pattern has the flag CASE_INSENSITIVE so all you need is

 Pattern pattern = Pattern.compile("^concat\\(",Pattern.MULTILINE+Pattern.CASE_INSENSITIVE);
Sascha
  • 1,057
  • 9
  • 14
  • The literal flag OP uses is fine too. But I agree flags in the factory method might make the pattern itself a little more readable. – Mena Apr 17 '19 at 13:16