The pattern() method of the Pattern class in Java is used to get the regular expression which is compiled to create this pattern. We use a regular expression to create the pattern and this method used to get the same source expression.
public String pattern()
Parameters: This method does not accepts anything as parameter.
Return Value: This method returns the pattern’s source regular expression.
Below programs illustrate the pattern() method:
Pattern's RegularExpression = (.*)(for)(.*)?
Pattern's RegularExpression = (.*)(ee)(.*)?
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.