国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

javascript字符串循環(huán)匹配實(shí)例分析

2019-11-20 12:01:44
字體:
供稿:網(wǎng)友

本文實(shí)例講述了javascript字符串循環(huán)匹配的方法。分享給大家供大家參考。具體如下:

采用exec和String.match方法,對(duì)于exec必須開啟全局匹配g標(biāo)識(shí)才能獲取所有匹配

// 需要提取這種數(shù)據(jù) <td>2012-12-17</td><td>11:02 , 12:25 , 13:22 , 15:06 , 15:12 , 19:22 , 23:47</td>var rawData = '<table><th align="left" scope="col">日期</th><th align="left" scope="col">簽到簽退時(shí)間</th></tr><tr class="GridViewRowStyle" style="height:20px;">'    + '<td>2012-12-03</td><td>10:16 , 13:22 , 20:05</td></tr><tr class="GridViewRowStyle" style="height:20px;">'    + '<td>2012-12-04</td><td>11:16 , 14:22 , 21:05</td></tr><table>';// 方法一var regexp = /<td>(/d{4}-/d{2}-/d{2})<//td><td>(.*?)<//td>/g;// 加上g標(biāo)識(shí)才會(huì)全局匹配,否則只匹配一個(gè)var matchedArray = regexp.exec(rawData);while(matchedArray != null) { console.dir(matchedArray); matchedArray = regexp.exec(rawData);}// 方法二var regexp = /<td>(/d{4}-/d{2}-/d{2})<//td><td>(.*?)<//td>/g;// 加上g標(biāo)識(shí)才會(huì)全局匹配var matchedArray = rawData.match(regexp);console.dir(matchedArray);// 方法三var regexp = /<td>(/d{4}-/d{2}-/d{2})<//td><td>(.*?)<//td>/;// 不加g標(biāo)識(shí)var matchedArray = rawData.match(regexp);console.dir(matchedArray);console.log(matchedArray.index);while(matchedArray != null) { rawData = rawData.substr(matchedArray.index + matchedArray[0].length); matchedArray = rawData.match(regexp);}console.dir(matchedArray);

希望本文所述對(duì)大家的javascript程序設(shè)計(jì)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 连城县| 封开县| 洪泽县| 鄂伦春自治旗| 浙江省| 海阳市| 循化| 商城县| 泸水县| 定边县| 玛沁县| 华宁县| 湟源县| 梅州市| 闽侯县| 偏关县| 汽车| 沅陵县| 原平市| 孟津县| 台北县| 靖安县| 河曲县| 建平县| 怀宁县| 遂川县| 成都市| 宜丰县| 明水县| 宣城市| 石狮市| 乳源| 江达县| 永川市| 米易县| 行唐县| 潍坊市| 嘉定区| 中山市| 贡山| 冕宁县|