Try

Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE

it should solve the issue. Or-ing the bitmask you will get compound features.

Answer from Roman C on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › tutorial › essential › regex › pattern.html
Methods of the Pattern Class (The Java™ Tutorials > Essential Java Classes > Regular Expressions)
Enter your regex: dog Enter input string to search: DoGDOg I found the text "DoG" starting at index 0 and ending at index 3. I found the text "DOg" starting at index 3 and ending at index 6. As you can see, the string literal "dog" matches both occurences, regardless of case. To compile a pattern with multiple flags, separate the flags to be included using the bitwise OR operator "|".
🌐
JRebel
jrebel.com › blog › java-regular-expressions-cheat-sheet
Java Regular Expressions (Regex) Cheat Sheet | JRebel
July 30, 2025 - Here are some flags that can be useful here and there. ... In our Regular Expressions cheat sheet, we include essential Java classes and methods, Regex syntax, character classes, boundary matchers, logical operations, quantifiers, groups, backreferences, and pattern flags.
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › util › regex › Pattern.html
Pattern (Java Platform SE 7 )
Predefined Character classes and POSIX character classes are in conformance with the recommendation of Annex C: Compatibility Properties of Unicode Regular Expression , when UNICODE_CHARACTER_CLASS flag is specified. Categories that behave like the java.lang.Character boolean ismethodname methods (except for the deprecated ones) are available through the same \p{prop} syntax where the specified property has the name javamethodname.
🌐
LogicBig
logicbig.com › tutorials › core-java-tutorial › java-regular-expressions › regex-embedded-flags.html
Java Regex modes, case insensitive, multiline, dot-all, comment/white-spaces, Unicode-Aware Case Folding, Literal Parsing, Unix Lines and Unicode Canonical Equivalence
That means regex '.+' will not match one or more characters but will match exactly '.+' in the input string. The flags CASE_INSENSITIVE and UNICODE_CASE retain their impact on matching when used along with this flag.
🌐
TutorialsPoint
tutorialspoint.com › javaregex › javaregex_pattern_flags.htm
java.util.regex.Pattern.flags() Method
The java.util.regex.Pattern.flags() method returns this pattern's match flags. Following is the declaration for java.util.regex.Pattern.flags() method. public int flags() The match flags specified when this pattern was compiled. The following example shows the usage of java.util.regex.Pattern.flags() method.
🌐
Educative
educative.io › answers › how-to-enable-multiple-flags-while-pattern-matching-in-java
How to enable multiple flags while pattern matching in Java
For example, in the expression below, we enable two different flags. Pattern pattern = Pattern.compile(regex, Pattern.COMMENTS | Pattern.CASE_INSENSITIVE);
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › regex › Pattern.html
Pattern (Java Platform SE 8 )
July 21, 2026 - The following Predefined Character classes and POSIX character classes are in conformance with the recommendation of Annex C: Compatibility Properties of Unicode Regular Expression , when UNICODE_CHARACTER_CLASS flag is specified. Categories that behave like the java.lang.Character boolean ismethodname methods (except for the deprecated ones) are available through the same \p{prop} syntax where the specified property has the name javamethodname.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › java › pattern-compilestringint-method-in-java-with-examples
Pattern compile(String,int) method in Java with Examples - GeeksforGeeks
February 6, 2023 - The Pattern class contains a list of flags (int constants) that can be helpful to make the Pattern matching behave in certain ways. For example, The flag name CASE_INSENSITIVE is used to ignore the case of the text at the time of matching.
🌐
Medium
medium.com › @sanjay.saravanan123 › mastering-regex-in-java-with-lookaheads-lookbehinds-flags-9ebc539a70f6
Mastering Regex in Java with Lookaheads, Lookbehinds & Flags | by Chanjay | Medium
September 16, 2025 - Regex flags (modifiers) are options that change how your regular expression behaves. In Java, you can pass them to Pattern.compile(regex, flags) or embed them inline inside the regex like (?i).
🌐
ZetCode
zetcode.com › java › regex-pattern-flags-method
Java Pattern.flags Method - Complete Tutorial with Examples
This example shows how to use the flags method to create a new Pattern with the same flags as an existing one. This is useful when you need to modify a regex but keep the same matching behavior. ... package com.zetcode; import java.util.regex.Pattern; public class PatternReuseFlags { public static void main(String[] args) { Pattern original = Pattern.compile("^start.*end$", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); // Get flags from original pattern int flags = original.flags(); // Create new pattern with same flags but different regex Pattern modified = Pattern.compile("^begin.*finish$", flags); System.out.println("Original flags: " + original.flags()); System.out.println("Modified flags: " + modified.flags()); // Verify both patterns have same flags System.out.println("Flags match: " + (original.flags() == modified.flags())); } }
🌐
Kodejava
kodejava.org › how-do-i-write-embedded-flag-expression
How do I write embedded flag expression? - Learn Java by Examples
May 31, 2023 - Another flag expressions are listed below: (?x), equivalent with Pattern.COMMENTS · (?m), equivalent with Pattern.MULTILINE · (?s), equivalent with Pattern.DOTTAL · (?u), equivalent with Pattern.UNICODE_CASE · (?d), equivalent with Pattern.UNIX_LINES · package org.kodejava.regex; import java.util.regex.Matcher; import java.util.regex.Pattern; public class EmbeddedFlagDemo { public static void main(String[] args) { // Define regex which starting with (?i) to enable // case-insensitive matching String regex = "(?i)the"; String text = "The quick brown fox jumps over the lazy dog"; // Obtain
🌐
Tabnine
tabnine.com › home › code library
Code Library - Tabnine
July 25, 2024 - Get the answers and suggestions you need from our AI code assistant. Get started in minutes with a free 90 day trial of Tabnine Pro.
🌐
TutorialsPoint
tutorialspoint.com › pattern-flags-method-in-java-with-examples
Pattern flags() method in Java with examples
The flags() method of this class returns the flag used in the current pattern. import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class COMMENTES_Example { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out...
🌐
Codecademy
codecademy.com › docs › java › regular expressions
Java | Regular Expressions | Codecademy
June 3, 2022 - Beginner Friendly.Beginner Friendly17 ... is: ... Where re is a regular expression pattern. And flags is an optional int bit mask specifying the flags for the pattern....
🌐
Baeldung
baeldung.com › home › java › core java › a guide to java regular expressions api
A Guide To Java Regular Expressions API | Baeldung
January 8, 2024 - This is because the matcher will look for the entire regex in the input text, including the spaces and the # character. But when we use the flag, it’ll ignore the extra spaces, and all text starting with # will be seen as a comment to be ignored for each line:
🌐
Dev.java
dev.java › learn › regex
Regular Expressions - Dev.java
Examines other useful methods of the Pattern class, and explores advanced features such as compiling with flags and using embedded flag expressions.
🌐
GeeksforGeeks
geeksforgeeks.org › java › pattern-flags-method-in-java-with-examples
Pattern flags() method in Java with Examples - GeeksforGeeks
April 17, 2023 - // Java program to demonstrate // Pattern.flags() method import java.util.regex.*; public class GFG { public static void main(String[] args) { // create a REGEX String String REGEX = "(.*)(for)(.*)?"; // create the string // in which you want to search String actualString = "code of Machine"; // compile the regex to create pattern // using compile() method Pattern pattern = Pattern.compile(REGEX, Pattern.CASE_INSENSITIVE); // find the flag of pattern int flag = pattern.flags(); System.out.println("Pattern's match flag = " + flag); } } Output: Pattern's match flag = 2 ·