Match
type
returns
Method
array<string>

Arguments

name
type
description
regex
regex
Regex to match string

Explanation

Returns an array of matched strings. When and if the g flag is provided, .match() returns all the matches in the string. Regardless of flags, .match() will always return a string array.

Examples

1
"Hello! Hi!".match(/H.+?!/) == ["Hello!"]
2
"Hello! Hi!".match(/H.+?!/g) == ["Hello!", "Hi!"]
Copied!
Last modified 1yr ago