Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

match method
javascript

What is the match() method JavaScript?

Educative Answers Team

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 string.match() is a built-in function in JavaScript; it is used to search a string, for a match, against a regular expression. If it returns an Array object the match is found, if no match is found a Null value is returned.


Syntax

The syntax for string.match() is shown below:

svg viewer

Regular expression

It has two things

  • an expression that needs to be searched or replaced

  • a modifier that modifies the search

svg viewer
modifiers meaning
g It searches the expression at all instances.
i It performs case-insensitive matching.

Examples

  1. This example shows a regular expression with a ‘g’ modifier
var data = 'Welcome to the Educative! Everyone likes Educative';
// regular expression with 'g' modifier
var regExp = /Educative/g;
// string.match() function.
var found = data.match(regExp);
// printing an array object.
console.log(found);
  1. This example shows a regular expression with a ‘i’ modifier
var data = 'Welcome to the Educative! Everyone likes Educative';
// regular expression with 'i' modifier
var regExp = /educative/i;
// string.match() function.
var found = data.match(regExp);
// printing an array object.
console.log(found);
  1. This example shows a regular expression with both a ‘g’ and an ‘i’ modifier
var data = 'Welcome to the Educative! Everyone likes Educative';
// regular expression with 'g' 'i' both modifier
var regExp = /educative/gi;
// string.match() function.
var found = data.match(regExp);
// printing an array object.
console.log(found);

RELATED TAGS

match method
javascript
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