bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Java/Java Reference
Java•Java Reference

Java String matches() Method

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind Java String matches() Method?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___ regex = "cat|dog|fish";
3Order

Put the learning moves in the order that makes the concept easiest to apply.

The matches() method searches a string for a match against a regular expression, and returns the matches.
Definition and Usage
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