Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

js
javascript

What is the string match() method in JavaScript?

Sarvech Qadir

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The method match() takes a regular expression (regex) and matches it against a provided string.

Syntax

string.match(reg_exp)

Parameters

reg_exp: The regular expression that is matched against the string.

Return value

The match() method returns an array containing the matches from the string.

Code

Here is a coded example of the match() method.

// lets look for all instances of 'ea' and 'in' in the following sentence.
let str = "What a beautiful weather in Berlin.";
console.log(str.match(/ea/g))
console.log(str.match(/in/g))

RELATED TAGS

js
javascript

CONTRIBUTOR

Sarvech Qadir
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring