Is Java RegEx case-insensitive?

后端 未结 5 864
死守一世寂寞
死守一世寂寞 2020-11-28 05:40

In Java, when doing a replaceAll to look for a regex pattern like:

replaceAll(\"\\\\?i\\\\b(\\\\w+)\\\\b(\\\\s+\\\\1)+\\\\b\", \"$1\"); 

(t

5条回答
  •  南笙
    南笙 (楼主)
    2020-11-28 06:40

    You can also match case insensitive regexs and make it more readable by using the Pattern.CASE_INSENSITIVE constant like:

    Pattern mypattern = Pattern.compile(MYREGEX, Pattern.CASE_INSENSITIVE);
    Matcher mymatcher= mypattern.matcher(mystring);
    

提交回复
热议问题