Pattern flags() method in Java with Examples Last Updated : 17 Apr, 2023 Comments Improve Suggest changes Like Article Like Report The flags() method of the Pattern class in Java is used to return the pattern's match flags. The Match flags are a bit mask that may include CASE_INSENSITIVE, MULTILINE, DOTALL, UNICODE_CASE, CANON_EQ, UNIX_LINES, LITERAL, UNICODE_CHARACTER_CLASS and COMMENTS Flags. Syntax: public int flags() Parameters: This method does not accepts any parameters. Return Value: This method returns the pattern's match flag. Below programs illustrate the flags() method: Program 1: Java // 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 Program 2: Java // 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 = "(.*)(ee)(.*)?"; // create the string // in which you want to search String actualString = "geeks"; // compile the regex to create pattern // using compile() method Pattern pattern = Pattern.compile(REGEX, Pattern.MULTILINE); // find the flag of pattern int flag = pattern.flags(); System.out.println("Pattern's match flag = " + flag); } } Output:Pattern's match flag = 8 References: https://docs.oracle.com/javase/10/docs/api/java/util/regex/Pattern.html#flags() Comment More infoAdvertise with us Next Article Pattern flags() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions Java 8 Java-Pattern Practice Tags : Java Similar Reads Period get() method in Java with Examples The get() method of Period class in Java is used to get the value of the requested unit(YEARS, MONTHS or DAYS) given in the argument from this Period. Syntax: public long get(TemporalUnit unit) Parameters: This method accepts a single parameter unit of type TemporalUnit which is the unit to get requ 2 min read Pattern toString() Method in Java with Examples toString() method of a Pattern class used to return the string representation of this pattern. This return the regular expression from which this pattern was compiled. Syntax: public String toString() Parameters: This method accepts nothing as parameter. Return value: This method returns a string re 1 min read Period from() method in Java with Examples The from() method of Period class in Java is used to get an instance of Period from given temporal amount. This function obtains a period based on the amount given in argument. A TemporalAmount represents an amount of time, which may be date-based or time-based. Syntax: public static Period from(Tem 1 min read Pattern asPredicate() Method in Java with Examples asPredicate() method of a Pattern class used to creates a predicate object which can be used to match a string.Predicate is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference. Syntax: public Predicate asPredicate() Parameters: This m 2 min read Field get() method in Java with Examples The get() method of java.lang.reflect.Field used to get the value of the field object. If Field has a primitive type then the value of the field is automatically wrapped in an object. If the field is a static field, the argument of obj is ignored; it may be null Otherwise, the underlying field is an 3 min read Like