ignore case regex

时间:2019-04-17 02:28:09

标签: java regex

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

1 个答案:

答案 0 :(得分:2)

Pattern具有标志CASE_INSENSITIVE,因此您所需要做的只是

 Pattern pattern = Pattern.compile("^concat\\(",Pattern.MULTILINE+Pattern.CASE_INSENSITIVE);