Curriculum
Course: Java Basic
Login

Curriculum

Java Basic

Java Home

0/1

Java Introduction

0/1

Java Get Started

0/1

Java Syntax

0/1

Java Comments

0/1

Java Type Casting

0/1

Java Operators

0/1

Java Booleans

0/1

Java Switch

0/1

Java Break / Continue

0/1

Java Errors and Exception

0/1
Text lesson

matches()

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.