- <textarea id=html_string style="width=100%" rows=8>
- <input
- type='text' value = 's>om
- " ething' name=names asdfasdf=asdf>
- </input>><input value=a>a name=aa><input name=bb value=bb>
- <input name=cc value=cc>
- </textarea>
- <script>
- var re = new Array()
- re[re.length] = Array("单标记 ", /<(/w+)[^"']*?((["'])?[^/3]*?/3[^"']*?)+>/ig)
- re[re.length] = Array("属性(带引号)", //w+/s*=/s*(["'])[^/1]*?/1/ig)
- re[re.length] = Array("属性(没引号)", //w+/s*=/s*/w+/gi)
- //alert(re.exec(ss))
- for (var i=0; i<re.length; i++)
- {
- document.write("<input type=radio name=re value="+i+">"+re[i][0]+" <input id=reValue size=100 type=text> ")
- document.write("<button onclick='re["+i+"][1]=document.all.reValue["+i+"].value'>保存</button>")
- document.write("<button onclick='document.all.reValue["+i+"].value=re["+i+"][1]'>恢复</button>
- ")
- document.all.reValue.length ? document.all.reValue[document.all.reValue.length-1].value = re[i][1] : document.all.reValue.value = re[i][1]
- }
- document.all.re[0].checked = true
- function matchTest()
- {
- var ss = html_string.innerText
- var re
- for (var i=0; i<document.all.re.length; i++) if(document.all.re[i].checked) break
- re = eval(document.all.reValue[i].value)
- rx = re.exec(ss)
- testArea.innerHTML = ""
- for (var i=1; i<9; i++) testArea.innerHTML += " RegExp$"+i+"="+eval("RegExp.$"+i)+" "
- rv = ss.match(re)
- for (var i=0; rv && i<rv.length; i++)
- {
- testArea.innerHTML += "<xmp style='background:#EEEEEE; padding:5px'>"+rv[i]+"</xmp>"
- }
- }
- </script>
- <button onclick=matchTest()>测试</button>
- <div id=testArea></div>
新闻热点
疑难解答