
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Pattern matcher() method in Java with examples
The java.util.regex package of java provides various classes to find particular patterns in character sequences.
The pattern class of this package is a compiled representation of a regular expression. The matcher() method of this class accepts an object of the CharSequence class representing the input string and, returns a Matcher object which matches the given string to the regular expression represented by the current (Pattern) object.
Example
import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class MatcherExample { public static void main(String args[]) { //Reading string value Scanner sc = new Scanner(System.in); System.out.println("Enter input string"); String input = sc.nextLine(); //Regular expression to find vowels String regex = "[aeiou]"; //Compiling the regular expression Pattern pattern = Pattern.compile(regex); //Retrieving the matcher object Matcher matcher = pattern.matcher(input); if(matcher.find()) { System.out.println("Given string contains vowels"); } else { System.out.println("Given string does not contain vowels"); } } }
Output
Enter input string RHYTHM Given string does not contain vowels
- Related Articles
- Matcher pattern() method in Java with Examples
- Matcher start() method in Java with Examples
- Matcher matches() method in Java with Examples
- Matcher replaceAll() method in Java with Examples
- Matcher replaceFirst() method in Java with Examples
- Matcher requireEnd() method in Java with Examples
- Matcher reset() method in Java with Examples
- Matcher toString() method in Java with Examples
- Matcher appendTail() method in Java with Examples
- Matcher group() method in Java with Examples
- Matcher groupCount() method in Java with Examples
- Matcher appendReplacement() method in Java with Examples
- Matcher regionEnd() method in Java with Examples
- Matcher regionStart() method in Java with Examples
- Matcher toMatchResult() method in Java with Examples

Advertisements