How to Make Java Regular Expression Case Insensitive in Java? Last Updated : 09 Mar, 2021 Comments Improve Suggest changes Like Article Like Report In this article, we will learn how to make Java Regular Expression case-insensitive in Java. Java Regular Expression is used to find, match, and extract data from character sequences. Java Regular Expressions are case-sensitive by default. But with the help of Regular Expression, we can make the Java Regular Expression case-insensitive. There are two ways to make Regular Expression case-insensitive: Using CASE_INSENSITIVE flagUsing modifier1. Using CASE_INSENSITIVE flag: The compile method of the Pattern class takes the CASE_INSENSITIVE flag along with the pattern to make the Expression case-insensitive. Below is the implementation: Java // 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. Welcome to gfg."; // Create pattern to match along // with the flag CASE_INSENSITIVE Pattern patrn = Pattern.compile( "gfg", Pattern.CASE_INSENSITIVE); // All metched patrn from str case // insensitive or case sensitive Matcher match = patrn.matcher(str); while (match.find()) { // Print matched Patterns System.out.println(match.group()); } } } OutputGFG gfg2. Using modifier: The " ?i " modifier used to make a Java Regular Expression case-insensitive. So to make the Java Regular Expression case-insensitive we pass the pattern along with the " ?i " modifier that makes it case-insensitive. Below is the implementation: Java // 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. Welcome to gfg."; // Create pattern to match along // with the ?i modifier Pattern patrn = Pattern.compile("(?i)gfg"); // All metched patrn from str case // insensitive or case sensitive Matcher match = patrn.matcher(str); while (match.find()) { // Print matched Patterns System.out.println(match.group()); } } } OutputGFG gfg Comment More infoAdvertise with us Next Article How to Make Java Regular Expression Case Insensitive in Java? N nikhilchhipa9 Follow Improve Article Tags : Java How To java-regular-expression Practice Tags : Java Similar Reads How to Use Regular Expression as a Substitute of endsWith() Method in Java? So primarily discuss what is endsWith() method is, so it is a method of String class that checks whether the string ends with a specified suffix. This method returns a boolean value true or false. Syntax: public boolean endsWith(String suff) Parameter: specified suffix part Return: Boolean value, he 3 min read Regular Expressions in Java In Java, Regular Expressions or Regex (in short) in Java is an API for defining String patterns that can be used for searching, manipulating, and editing a string in Java. Email validation and passwords are a few areas of strings where Regex is widely used to define the constraints. Regular Expressi 7 min read How to validate a Username using Regular Expressions in Java Given a string str which represents a username, the task is to validate this username with the help of Regular Expressions. A username is considered valid if all the following constraints are satisfied: The username consists of 6 to 30 characters inclusive. If the username consists of less than 6 or 3 min read Case insensitive search in JavaScript Case-insensitive: It means the text or typed input that is not sensitive to capitalization of letters, like "Geeks" and "GEEKS" must be treated as same in case-insensitive search. In Javascript, we use string.match() function to search a regexp in a string and match() function returns the matches, a 2 min read MatchResult group(int) method in Java with Examples The group(int group) method of MatchResult Interface is used to get the group index of the match result already done, from the specified group. Syntax: public String group(int group) Parameters: This method takes a parameter group which is the group from which the group index of the matched pattern 2 min read Like