# The String match() method

> Learn how the JavaScript match() method runs a regular expression against a string and returns an array of matches and capture groups, or null if none match.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2019-02-23 | Topics: [JavaScript](https://flaviocopes.com/tags/js/) | Canonical: https://flaviocopes.com/javascript-string-match/

Given a regular expression identified by `regex`, try to match it in the string.

> Tip: try these examples yourself in my [regex tester](https://flaviocopes.com/tools/regex-tester/) — it highlights matches and capture groups live.

Examples:

```js
'Hi Flavio'.match(/avio/)
// Array [ 'avio' ]

'Test 123123329'.match(/\d+/)
// Array [ "123123329" ]

'hey'.match(/(hey|ho)/)
//Array [ "hey", "hey" ]

'123s'.match(/^(\d{3})(\w+)$/)
//Array [ "123s", "123", "s" ]

'123456789'.match(/(\d)+/)
//Array [ "123456789", "9" ]

'123s'.match(/^(\d{3})(?:\s)(\w+)$/)
//null

'123 s'.match(/^(\d{3})(?:\s)(\w+)$/)
//Array [ "123 s", "123", "s" ]

'I saw a bear'.match(/\bbear/)    //Array ["bear"]

'I saw a beard'.match(/\bbear/)   //Array ["bear"]

'I saw a beard'.match(/\bbear\b/) //null

'cool_bear'.match(/\bbear\b/)     //null
```

To know more about Regular Expressions, see my [Regular Expressions tutorial](https://flaviocopes.com/javascript-regular-expressions/).
