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

How to use the match function in JavaScript

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

JavaScript match function how to use, many novices are not very clear about this, in order to help you solve this problem, the following small series will explain in detail for everyone, there are people who need this can learn, I hope you can gain something.

Function: Performs a lookup on a string using regular expression patterns and returns the results containing the lookup as an array

Function format: stringObj.match(rgExp) stringObj is required for string rgExp is required for regular expression

Return value: if it can match, return result array; if it cannot match, return null.

The copy code is as follows:

//Performs a lookup on a string using a regular expression pattern and returns the results containing the lookup as an array

var objStr=new String("Yue I love you till the end of my life! ");

var re=//wo(/w+)?/ g;//This expression is used to match a character represented by/w, the second character is o, followed by one or more characters + indicates the number of times the previous character matches, global match

var arr=objStr.match(re);//Call match method matches string and returns array if there is one, null if no result

[xss_clean]("string before match:"+objStr+"

");//output string before matching

if(arr!= null){//If the match succeeds, the arr array is not empty, and the loop outputs the result.

for(var i=0;i

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