Java Pattern flags() Method
Example
Get the flags of a pattern with no flags, and of a pattern that ignores upper and lower case:
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
Pattern pattern1 = Pattern.compile("w3schools");
Pattern pattern2 = Pattern.compile("w3schools", Pattern.CASE_INSENSITIVE);
System.out.println(pattern1.flags());
System.out.println(pattern2.flags());
}
}
Definition and Usage
The flags() method returns the flags (options) that were used when the pattern was created with compile().
Each flag is a number. For example, Pattern.CASE_INSENSITIVE is 2. The value 0 means that no flags were used. If you use more than one flag, the result is the flags added together.
Syntax
public int flags()
Parameter Values
None.
Technical Details
| Returns: | The flags as an int, or 0 if no flags were used. |
|---|
Related Pages
❮ RegEx Methods