The Pattern class
The Pattern
class represents the compiled form of a string regular expression. So far, we have provided all the regular expressions as strings. Each String regular expression must be compiled into an instance of the Pattern
class before the Java regex engine can execute it. An instance of the Pattern
class is used to create a Matcher
object to match input text against the regular expression.
Let's list down the important and useful methods from the Pattern
class first:
Method Signature | Description |
Static Pattern compile(String regex) | Compiles the given String regular expression into a |
Static Pattern compile(String regex, int flags) | Compiles the given String regular expression into a Pattern instance with the given flags. Flags can be one or more of |