javascript字符串循环匹配的实例分析

本文介绍了javascript字符串的循环匹配方法,供大家参考:

使用exec和string.match方法、全局匹配g标识符必须打开为EXEC得到所有的比赛


需要提取数据 / / 2012-12-1711:02,12:25,13:22,15时06分,15:12,19:22,47
VaR数据=日期签到签退时间
+ '2012-12-0310:16,13:22,20:05
+ '2012-12-0411:16,14:22,21:05;
方法
var = regexp /( D { 4 } - D { 2 } - D { 2 })( / G);
g标志将是全局匹配,否则为
无功matchedarray = regexp.exec(原始数据);
而(matchedarray!= NULL){
Console.dir(matchedarray);
matchedarray = regexp.exec(原始数据);
}
两种方法
var = regexp /( D { 4 } - D { 2 } - D { 2 })( / G);
添加G标志将是全局匹配。
无功matchedarray = rawdata.match(正则表达式);
Console.dir(matchedarray);
三 /方法
var = regexp /( D { 4 } - D { 2 } - D { 2 })/(。*);
不带id
无功matchedarray = rawdata.match(正则表达式);
Console.dir(matchedarray);
console.log(matchedarray。指数);
而(matchedarray!= NULL){
来源= rawdata.substr(matchedarray.index + matchedarray { 0 }。长度);
matchedarray = rawdata.match(正则表达式);
}
Console.dir(matchedarray);




希望本文能对大家的javascript程序设计有所帮助。