Java Pattern pattern() Method
Example
Get the regular expression of a pattern:
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
Pattern pattern = Pattern.compile("[0-9]+");
System.out.println(pattern.pattern());
}
}
Definition and Usage
The pattern() method returns the regular expression that the Pattern object was created from, as a String.
In the example, [0-9]+ means "one or more digits from 0 to 9".
Syntax
public String pattern()
Parameter Values
None.
Technical Details
| Returns: | The regular expression, as a String. |
|---|
Related Pages
❮ RegEx Methods