❮ String Methods
Example
String regex = "cat|dog|fish";
System.out.println("cat".matches(regex));
System.out.println("dog".matches(regex));
System.out.println("catfish".matches(regex));
System.out.println("doggy bag".matches(regex));Definition and Usage
The matches() method searches a string for a match against a regular expression, and returns the matches.
Syntax
public String matches(String
regex )Parameter Values
| Parameter | Description |
|---|---|
| regex | A regular expression |
Technical Details
| Returns: | A boolean value: true if the regular expression exactly matches the string false if it does not match the string. |
|---|