JavaScript match()Method
Examples
Find "ain" in the string:
nOutput the resulting array values:
Try it Yourself »
Definition and Usage
The match() method searches a string for a specified value, or finds one or more matches of a regular expression.
If you want to learn more about regular expression tutorials, please check out this site's:RegExp Tutorialand ourRegExp Object Reference Manual。
Note:The match() method searches a string object to find one or more texts that match regexp. The behavior of this method depends largely on whether regexp has the flag g. If regexp does not have the flag g, then the match() method can only perform one match in stringObject. If no matching text is found, match() will return null. Otherwise, it will return an array containing information about the matching text it found.
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the match() method
Syntax
Parameter Values
| Parameter | Description |
|---|---|
| regexp | Required. Specifies a RegExp object of the pattern to be matched. If this parameter is not a RegExp object, it must first be passed to the RegExp constructor to convert it into a RegExp object. |
Return Value
| Type | Description |
|---|---|
| Array | An array storing the matching results. The content of this array depends on whether regexp has the global flag g. Returns null if no matching result is found.null 。 |
Technical Details
| JavaScript Version: | 1.2 |
|---|
More Examples
Example
Search for the string "ain" globally, case-insensitive:
nOutput result:
Try it Yourself »
Example
Check if it is a WeChat browser:
Try it Yourself »
Other Extensions
JavaScript String Object