bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths

Loading lesson path

Learn/Java/Java Reference
Java•Java Reference

Java String matches() Method

❮ 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

ParameterDescription
regexA 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.

Previous

Java String length() Method

Next

Java String offsetByCodePoints() Method