Usage of the match method: Retrieve the results matching the regular expression in the string and return the matching items as Array objects. The syntax of the match method is "string.match(param)", where the parameter "param ” represents a regular expression object. The
match
method is used to retrieve the results that match the regular expression in the string and return the matching items as an Array object. So in this article we will talk about the basic usage of the match method.
Let’s first take a look at the basic syntax of the match method
string.match( param )
param represents a regular expression object.
Note: If the regular expression does not contain the g modifier (performing a global search), the match() method will only return the first match in the string.
If no match is found, this method returns null.
Let’s look at a specific example
The code is as follows
<!DOCTYPE html> <html> <head> <title>JavaScript String match() Method</title> </head> <body> <script type = "text/javascript"> var str = "For more information, see Chapter 3.4.5.1"; var re = /(chapter \d+(\.\d)*)/i; var found = str.match( re ); document.write(found ); </script> </body> </html>
The display effect on the browser is: Chapter 3.4.5.1,Chapter 3.4.5.1,.1
This article ends here. For more exciting content, you can pay attention to the relevant column tutorials on the php Chinese website! ! !
The above is the detailed content of How to use match method. For more information, please follow other related articles on the PHP Chinese website!