The compile() method of Pattern class is used to compile the given regular expression passed as the string. It used to match text or expression against a regular expression more than one time.
Signature
SN | Method | Description |
---|---|---|
1 | static Pattern compile(String regexp) | Return compiled version of a regular expression into the pattern. |
2 | static Pattern compile(String regexp, int flags) | Return compiled version of a regular expression into the pattern with the given flag. |
Pattern Class, which summarizes of the regex patterns. Processing matching result matcher.group: returns the input subsequence matched by the previous match. Matcher.start: returns the start index of the. Java Regex by Examples. Matcher object interprets the pattern and performs match operations. See a few examples on how to use capturing groups in Java regex API.
Parameter
regexp - The expression that we want to compile.
flags - Match flags, a bit mask that may include
Returns
The given regular expression compiled into a pattern
Throws
PatternSyntaxException - If the expression's syntax is invalid
Example 1
Test it NowOutput:
Example 2
Test it NowOutput:
Example 3
Test it NowOutput:
Example 4
Test it NowOutput:
![Examples Examples](/uploads/1/2/6/5/126522772/474599169.png)
Next TopicJava Regex
- Java Regex Tutorial
- Java Regex Examples
- Java Regex Useful Resources
- Selected Reading
Description
The java.time.Matcher.group() method attempts to find the next subsequence of the input sequence that matches the pattern.
Declaration
Following is the declaration for java.time.Matcher.group() method.
Return Value
The (possibly empty) subsequence matched by the previous match, in string form.
- IllegalStateException − If no match has yet been attempted, or if the previous match operation failed.
Example
The following example shows the usage of java.time.Matcher.group() method.
Let us compile and run the above program, this will produce the following result −
javaregex_matcher.htm