java.util.regex.Pattern.flags() Method



Description

The java.util.regex.Pattern.flags() method returns this pattern's match flags.

Declaration

Following is the declaration for java.util.regex.Pattern.flags() method.

public int flags()

Return Value

The match flags specified when this pattern was compiled.

Example

The following example shows the usage of java.util.regex.Pattern.flags() method.

package com.tutorialspoint;

import java.util.regex.MatchResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PatternDemo {
   private static final String REGEX = "(.*)(\\d+)(.*)?# 3 capturing groups";
   private static final String INPUT = "This is a sample Text, 1234, with numbers in between.";

   public static void main(String[] args) {
      // create a pattern
      Pattern pattern = Pattern.compile(REGEX,Pattern.COMMENTS);
      
      // get a matcher object
      Matcher matcher = pattern.matcher(INPUT); 
      System.out.println(pattern.flags());
   }
}

Let us compile and run the above program, this will produce the following result −

4
javaregex_pattern.htm
Advertisements