String regex = "cat|dog|fish";
System.out.println("cat".matches(regex));
ystem.out.println("dog".matches(regex));
System.out.println("catfish".matches(regex));
System.out.println("doggy bag".matches(regex));
|
Example
Verify if a string conforms to the specified regular expression.
Definition and Usage
The matches() method scans a string for a match with a regular expression and provides the matching results.
Syntax
public String matches(String regex)
|
Parameter Values
|
Parameter
|
Description
|
|
regex
|
A pattern expressed in regular expression syntax.
|
Technical Details
|
Returns:
|
A boolean value:
- true if the regular expression precisely matches the string.
- false if there is no match with the string.
|