Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the parameters of es6's match

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "what are the parameters of the match of es6". In the daily operation, I believe that many people have doubts about the parameters of the match of es6. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "what parameters are the match of es6?" Next, please follow the editor to study!

Es6 match () takes only one parameter. The match () method is used to retrieve matches, either to retrieve a specified value within a string, or to find a match for one or more regular expressions, the syntax "String.match (regexp)"; this method takes only one parameter, which specifies the regular expression object of the pattern to match.

The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.

The match () method is used to retrieve matches, either to retrieve a specified value within a string, or to find a match for one or more regular expressions.

The match () method has only one parameter, syntactically formatted:

String.match (regexp)

The parameter regexp: is a regular expression object, a required parameter that specifies the RegExp object of the pattern to match. If the parameter is not a RegExp object, you need to first pass it to the RegExp constructor to convert it to a RegExp object.

Return value

If you use the g flag, all results that match the full regular expression are returned, but no capture group is returned.

If the g flag is not used, only the first full match and its associated capture group (Array) are returned. In this case, the returned project will have other properties as described below.

Description

The match () method retrieves the string string to find one or more text that matches the regexp. The behavior of this method depends to a large extent on whether regexp has the flag g.

If regexp does not have a flag g, then the match () method can only perform a match once in the string. If no matching text is found, match () returns null. Otherwise, it returns an array of information about the matching text it finds. The 0th element of the array holds matching text, while the rest of the elements hold text that matches the child expression of the regular expression. In addition to these regular array elements, the returned array contains two object properties. The index attribute declares the position of the starting character of the matching text in the string, and the input attribute declares a reference to the stringObject.

If regexp has the flag g, the match () method performs a global search to find all matching substrings in the string. If no matching substring is found, null is returned. If one or more matching substrings are found, an array is returned. However, the contents of the array returned by the global match are quite different from the former, in which all the matching substrings in stringObject are stored in the array elements, and there are no index or input attributes.

Note: in global retrieval mode, match () does not provide information about the text that matches the subexpression, nor does it declare the position of each matching substring. If you need this globally retrieved information, you can use RegExp.exec ().

Example 1:

Use match to find "Chapter" followed by one or more numeric characters, followed by a decimal point and numeric characters 0 or more times. The regular expression contains the I flag, so case is ignored.

Var str = 'For more information, see Chapter 3.4.5.1) / see (chapter\ d + (\.\ d) *) / console.log (re); console.log (found)

Example 2:match uses global (global) and ignore case (ignore case) flags

Shows how match uses the global and ignore case flags. All the letters of Amure and Amure will be returned as elements of an array.

Var str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';var regexp = / [Amure] / gi;var matches_array = str.match (regexp); console.log (matches_array)

At this point, the study of "what are the parameters of the match of es6" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report