国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 洛隆县| 五大连池市| 三河市| 弥勒县| 巴林左旗| 嫩江县| 喜德县| 广东省| 盐山县| 云浮市| 闵行区| 福鼎市| 西吉县| 吐鲁番市| 明光市| 榕江县| 丹凤县| 资溪县| 乌鲁木齐县| 博罗县| 深州市| 同德县| 舒兰市| 阿合奇县| 泗洪县| 炎陵县| 广饶县| 安龙县| 方正县| 遂宁市| 阿坝| 张家界市| 邵武市| 太原市| 老河口市| 丰宁| 印江| 南平市| 松原市| 鸡西市| 南和县|