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

The function of index attribute of js regular expression

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the knowledge of "the index attribute function of js regular expressions". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Function: the value returned by index and search is the same, regardless of whether it matches the appropriate content or not. If the appropriate content is found, index is the starting position of the actual character of the matching content. If not,-1 is returned.

Basic syntax RegExp.index

Note: this property is also a static property of RegExp and is called in a fixed way.

The copy code is as follows:

/ / alert ('Designed By Androidyue'); / / set the regular expression to match the same number of digits like 12021, ten digits and thousands of digits, and non-global matching only once var re=/ (/ d) (/ d) / dplash 2; / / var re=/3 (/ d+) /; / the data var objStr='1101011100110101100110011001' to be matched / / use the search method to match the starting position of the content for the first time back to Shanghai. Note that the first address of the string is 0, not 1 var pos=objStr.search (re); / / if the search method does not find a suitable match, it returns 1 if (pos==-1) {/ / [xss_clean] ("No matching content found!" + RegExp.index); [xss_clean] (("No matching content was found!") ;} else {/ / if the search method can find the appropriate matching content, it returns var arr=objStr.match (re) of the starting string of the matching content; / / stores the appropriate matching content in the array [xss_clean] ("the first match is found at" + pos+ "position, the matching content is" + arr [0] + ").

"); [xss_clean] (" the value of RegExp.index at this time is "+ RegExp.index"); / / displays 1 in the ie core browser (like pos), and shows undefined} "index attribute function of js regular expression" in chrome,ff,opera. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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

Internet Technology

Wechat

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

12
Report