|
![]() |
名片设计 CorelDRAW Illustrator AuotoCAD Painter 其他软件 Photoshop Fireworks Flash |
|
覆盖原execIt函数 修改后的execIt函数答应对多个正则表达式进行匹配(每个正则表达式一行),并对每一个匹配成分显示出是第几个正则表达式匹配的。 这可视为语法分析的雏形,只要对匹配产生相应的动作。 function execIt(form) { var mode if(form.chkmode.checked) mode = "gi" else mode = "g" var regexpArray = form.regexp.value.split("rn") //获取正则表达式到数组 if(nextpoint == 0) form.reglist.value = "" var key = true if(form.scankmode.checked) key = false else nextpoint = 0 do { var offs = 9999999999 var pos = -1 var input = form.main.value.substr(nextpoint) //对每个正则表达式进行匹配 for(var i=0;i<regexpArray.length;i++) { re.compile(regexpArray[i],mode) var matchArray = re.exec(input) if(matchArray) { if(offs > matchArray.index) { offs = matchArray.index pos = i //保存距离起始位子最近的匹配 } } } if(pos>=0) { re.compile(regexpArray[pos],mode) var matchArray = re.exec(input) for(var i=1;i<matchArray.length;i++) matchArray[i] = "$"+i+":"+matchArray[i] form.reglist.value = "["+(pos+1)+"]"+(nextpoint+matchArray.index)+" => " + matchArray[0] +"n"+form.reglist.value form.matchlist.value = "$0:"+matchArray.join("n") nextpoint = nextpoint + matchArray.index + matchArray[0].length }else { if(!key) form.reglist.value = "没有找到n" + form.reglist.value form.matchlist.value = " " nextpoint = 0 key = false } }while(key) } 返回类别: 教程 上一教程: 使用FSO按文件大小浏览文件目录并进行删除操作 下一教程: 在ASP中利用“正则表达式” 对象实现UBB风格的论坛 您可以阅读与"对正则表达式训练器的改进"相关的教程: · 正则表达式简介(12) · 实现搜索结果的要害词变色标注的程序(使用正则表达式) · ASP正则表达式在UBB论坛中的应用 · 正则表达式在网页处理中的应用四则 · 用正则表达式写的HTML分离函数 |
![]() ![]() |
快精灵印艺坊 版权所有 |
首页![]() ![]() ![]() ![]() ![]() ![]() ![]() |