- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Matcher.pattern() method in Java Regular Expressions
The method java.time.Matcher.pattern() returns the pattern that is matched upon by the Matcher. This method accepts no parameters.
A program that demonstrates the method Matcher.pattern() in Java regular expressions is given as follows −
Example
import java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo { public static void main(String args[]) { String regex = "Apple"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher("AppleIsAFruit"); System.out.println("Pattern: " + m.pattern()); } }
The output of the above program is as follows −
Pattern: Apple
Now let us understand the above program.
The pattern that is matched upon by the Matcher is returned using the Matcher.pattern() method and then printed. A code snippet which demonstrates this is as follows −
String regex = "Apple"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher("AppleIsAFruit"); System.out.println("Pattern: " + m.pattern());
- Related Articles
- Reset the Matcher in Java Regular Expressions
- Pattern matcher() method in Java with examples
- Matcher pattern() method in Java with Examples
- Pattern.matches() method in Java Regular Expressions
- Working with Matcher.start() method in Java Regular Expressions
- Working with Matcher.end() method in Java Regular Expressions
- Role of Matcher.matches() method in Java Regular Expressions
- Role of Matcher.group() method in Java Regular Expressions
- Which package is used for pattern matching with regular expressions in java?
- Role of Matcher.find(int) method in Java Regular Expressions
- Java Regular Expressions Tutorial
- Greedy quantifiers Java Regular expressions in java.
- Back references in Java regular expressions
- Regular Expressions syntax in Java Regex
- Regex quantifiers in Java Regular Expressions

Advertisements