In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "the introduction of js regular expression exec method". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the introduction of js regular expression exec method".
Function description: this function obtains the content of the first regular expression in the string by matching your string, and stores the matching content and the result of the sub-match in the return array.
Basic method: objReg.exec (string)
Name of the objReg,RegExp object
String, the string to match
The regular expression exec () function:
The exec () method is used to retrieve the match of a regular expression in a string.
The return value is an array, but the contents of this array have a lot to do with whether the regular object is a global match:
1. There is no g modifier:
In non-global matching mode, the function of this function is the same as the match () function. It can only be matched once in a string. If no matching string is found, null is returned, otherwise an array is returned. The 0th element of the array stores the matching string, and the first element stores the matching string of the first referential grouping (subexpression). The second element holds the string matched by the second referential grouping (subexpression), and so on. At the same time, this array also includes two object properties, the index attribute declares the position of the starting character of the matching string in the complete string to match, and the input attribute declares a reference to the complete string to match.
Special note:
In non-global matching mode, IE browsers also have the lastIndex property, but in this case it is read-only.
two。 With the g modifier:
In global matching mode, the return value of this function is also an array and can only be matched once in a string. At this point, however, this function usually matches the lastIndex property, and this function starts retrieving the string at the character specified by the lastIndex attribute, and when exec () finds a string that matches the expression, it sets the lastIndex property to the next position of the last character of the matching string after the match. You can iterate through all matches in the string by calling the exec () function repeatedly, and when the exec () function can no longer find the matching text, it returns null and resets the lastIndex property to 0.
The content structure of the array is exactly the same as without the g modifier.
Special note:
If you want to start retrieving a new string after completing a pattern match in a string, you must manually reset the lastIndex property to 0.
Grammatical structure:
RegExpObject.exec (string)
The list of parameters is as follows:
Parameter name semantic interpretation string is required. The string to retrieve.
Browsers support:
IE browsers support this method.
Firefox browser supports this method.
Google browser supports this method.
Example code:
Example 1:
Var str= "I love antzone, this is animate"; var reg=/an/;console.log (reg.exec (str))
Example 2:
Var str= "the name 123 and 456"; var reg=/\ d Maxima greg.lastIndexForm15positionconsole.log (reg.exec (str))
In global mode, you can use the lastIndex property to set the position where the specified character is found in the string.
/ / set the matching string var objStr= "my mobile number 13522222222, his mobile number 13288888888, her mobile number 13699999999"; / / set the regular expression to match the 11-bit string starting with 13, and globally match var reg=/13 (/ d) (/ d {8}) / g / / execute the exec function, although it is a global matching regular expression, but the exec method matches the specified string only once, gets the first content in the string that you want to match with the regular expression, and stores the matching content and the result of the submatch in the returned array var arr=reg.exec (objStr); / / loops the output result for (var item0
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.