JavaScript Glossary: String match()
Publikováno: 27.3.2019
Basics
This method is a called against a regular expression and returns the matching values in the string. The return value is an array containing the matched values. If no matches are fo...
Basics
This method is a called against a regular expression and returns the matching values in the string. The return value is an array containing the matched values. If no matches are found within the string, null
is returned.
"hello world".match(/[el]/gi)
// ["e", "l", "l", "l"]
https://scotch.io/embed/gist/ab1c47b60065848a754ebd6f10510b59
Syntax
const matchedStrings = string.match(regex)
1 Parameter
regex
This is the regular expression to search for within the string - required
Returns an array
It returns an array of all matched characters in the string.
Common Uses and Snippets
Extract specific information from a string
This method can be used to extract info from a string. Like getting an email address from a sentence.
https://scotch.io/embed/gist/a6d3eff461b68a173889377b949e2a66