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);
Answer from Christian Vielma on Stack Overflow
🌐
Baeldung
baeldung.com › home › java › java string › case-insensitive string matching in java
Case-Insensitive String Matching in Java | Baeldung
August 28, 2025 - We looked at using String.toLowerCase() and toUpperCase(), String.matches(), String.regionMatches(), Apache Commons StringUtils.containsIgnoreCase(), and Pattern.matcher().find(). Also, we evaluated the performance of each solution and found that using the compile() method from java.util.regex.Pattern with the CASE_INSENSITIVE flag performed the best.
🌐
Mkyong
mkyong.com › home › regular expressions › regular expression case sensitive example – java
Regular Expression case sensitive example - Java - Mkyong.com
September 7, 2013 - package com.mkyong.regex import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; public class RunExampleTest{ private Pattern registrarPattern = Pattern.compile(REGISTRAR_PATTERN); //alternative /*private Pattern registrarPattern = Pattern.compile(REGISTRAR_PATTERN, Pattern.CASE_INSENSITIVE);*/ private Matcher matcher; private static final String REGISTRAR_PATTERN = "(?)Registrar:\\s(.*)"; public static void main(String[] args) { String data = "Testing...
🌐
Alvin Alexander
alvinalexander.com › blog › post › java › java-how-case-insensitive-search-string-matches-method
Java: How to perform a case-insensitive search using the String ‘matches’ method | alvinalexander.com
September 30, 2019 - */ public class StringMatchesCaseInsensitive { public static void main(String[] args) { String stringToSearch = "Four score and seven years ago our fathers ..."; // this won't work because the pattern is in upper-case System.out.println("Try 1: " + stringToSearch.matches(".*SEVEN.*")); // the magic (?i:X) syntax makes this search case-insensitive, so it returns true System.out.println("Try 2: " + stringToSearch.matches("(?i:.*SEVEN.*)")); } } ... This is a trivial example that you could solve using other techniques, but when you have a more complex pattern that you're trying to find, this "magic" case-insensitive syntax can come in handy. For more information on this syntax see the Pattern javadoc page on Sun's web site.
🌐
Oracle
docs.oracle.com › javase › tutorial › essential › regex › pattern.html
Methods of the Pattern Class (The Java™ Tutorials > Essential Java Classes > Regular Expressions)
The expression "a\u030A", for example, will match the string "\u00E5" when this flag is specified. By default, matching does not take canonical equivalence into account. Specifying this flag may impose a performance penalty. Pattern.CASE_INSENSITIVE Enables case-insensitive matching.
🌐
Kodejava
kodejava.org › how-do-i-match-a-regex-pattern-in-case-insensitive
How do I match a regex pattern in case-insensitive? - Learn Java by Examples
May 30, 2023 - package org.kodejava.regex; import java.util.regex.Pattern; import java.util.regex.Matcher; public class RegexIgnoreCaseDemo { public static void main(String[] args) { String sentence = "The quick brown fox and BROWN tiger jumps over the lazy dog"; Pattern pattern = Pattern.compile("brown", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(sentence); while (matcher.find()) { System.out.format("Text \"%s\" found at %d to %d.%n", matcher.group(), matcher.start(), matcher.end()); } } } Here is the result of the program: Text "brown" found at 10 to 15.
🌐
Educative
educative.io › answers › what-is-patterncaseinsensitive-in-java
What is Pattern.CASE_INSENSITIVE in Java?
Case-insensitive pattern matching can be achieved by passing the Pattern.COMMENTS flag as the match flag. import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static void main(String[] args) { String string ...
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-make-java-regular-expression-case-insensitive-in-java
How to Make Java Regular Expression Case Insensitive in Java? - GeeksforGeeks
March 9, 2021 - // Java program demonstrate How to make Java // Regular Expression case insensitive in Java import java.util.regex.Matcher; import java.util.regex.Pattern; class GFG { public static void main(String[] args) { // String String str = "From GFG class.
🌐
TutorialsPoint
tutorialspoint.com › How-to-test-if-a-Java-String-contains-a-case-insensitive-regex-pattern
How to test if a Java String contains a case insensitive regex pattern
June 24, 2020 - public class RegCaseSense { public ... = "HI we are at java class."; // this won't work because the pattern is in upper-case System.out.println("Try this 1: " + stringSearch.matches(".*CLASS.*")); // the magic (?i:X) syntax makes this search case-insensitive, so it returns true ...
🌐
Alvin Alexander
alvinalexander.com › blog › post › java › how-find-string-case-insensitive-regex-pattern-matcher-2
Java: How to test if a String contains a case-insensitive regex pattern | alvinalexander.com
July 8, 2016 - */ public class PatternMatcherFind3Regex { public static void main(String[] args) { // the string we want to search String stringToSearch = "FOUR SCORE AND SEVEN YEARS AGO OUR FATHERS ..."; // search for this simple pattern String patternToSeachFor = " ye.* "; // set everything up Pattern p = Pattern.compile(patternToSeachFor, Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(stringToSearch); // now see if we find a match if (m.find()) System.out.println("Found a match"); else System.out.println("Did not find a match"); } }
🌐
Bennadel
bennadel.com › blog › 301-case-insensitive-java-regular-expressions-how-did-i-miss-that.htm
Case Insensitive Java Regular Expressions - How Did I Miss That!?!
March 22, 2020 - I have been doing regular expressions for a long time now and this one has escaped me. Crazy! But, it's so awesome. You just put the flag (?i) in your regular expression and everything to the right of it will be case-insensitive: <!--- Set string value. ---> <cfset strText = "Libby is FUNNY" /> <!--- Check case-sensitive match.
🌐
CodingTechRoom
codingtechroom.com › question › case-insensitive-regex-java
How to Perform Case-Insensitive Regex Matching in Java? - CodingTechRoom
String result = inputString.replaceAll("(?i)\b(\w+)\b(\s+\1)+\b", "$1"); // Case-insensitive duplicate removal · Java supports case-insensitive matching in regex through the use of inline flags. To achieve this, you can use the `(?i)` flag directly in your regex pattern.
🌐
Rip Tutorial
riptutorial.com › ignore case modifier
Regular Expressions Tutorial => IGNORE CASE modifier
In Java, by default, case-insensitive matching assumes that only characters in the US-ASCII charset are being matched. Unicode-aware case-insensitive matching can be enabled by specifying the UNICODE_CASE flag in conjunction with this ...
🌐
TutorialsPoint
tutorialspoint.com › pattern-case-insensitive-field-in-java-with-examples
Pattern CASE_INSENSITIVE field in Java with examples
November 20, 2019 - import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class CASE_INSENSITIVE_Example { public static void main( String args[] ) { Scanner sc = new Scanner(System.in); System.out.println("Enter input data: "); String input = sc.nextLine(); System.out.println("Enter required character: "); char ch = sc.next().toCharArray()[0]; //Regular expression to find the required character String regex = "["+ch+"]"; //Compiling the regular expression Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); //Retrieving the matcher object Matcher matcher = pattern.matcher(input); int count =0; while (matcher.find()) { count++; } System.out.println("The letter "+ch+" occurred "+count+" times in the given text (irrespective of case)"); } }
🌐
DeepSource
deepsource.com › directory › java › issues › JAVA-E1010
Case insensitive regex does not properly handle Unicode input (JAVA-E1010) ・ Java
To remedy this, Java provides the Pattern.UNICODE_CASE and Pattern.UNICODE_CHARACTER_CLASS flags which can be used in tandem with the CASE_INSENSITIVE flag to extend the case insensitive behavior to non-ASCII characters. The (?u) and (?U) regex group constructs can also be used in place of these flags to achieve the same purpose. input = "Смотри́"; // The regex tries to match the string ...
🌐
CodingTechRoom
codingtechroom.com › tutorial › java-java-case-insensitive-string-matching
Java Case Insensitive String Matching: A Comprehensive Guide - CodingTechRoom
In this tutorial, we've explored various methods for performing case insensitive string matching in Java. From simple equality checks using `equalsIgnoreCase()` to more complex comparisons using regex, these techniques are essential for building user-friendly applications.