欢迎光临
我们一直在努力

正则表达式练习测试页-ASP教程,正则表达式

建站超值云服务器,限时71元/月

前段时间差不多都要和正则表达式打交道,所以当时就弄了这个测试练习页面.把以下代码保存为一个html文件用ie打开即可使用:

<!doctype html public "-//w3c//dtd html 4.01 transitional//en"

"http://www.w3.org/tr/html4/loose.dtd">

<html>

<head>

<meta http-equiv="content-type" content="text/html; charset=gb2312">

<title>正则表达式测试</title>

<style type="text/css">

<!–

td {

font-family: "宋体";

font-size: 12px;

color: #666666;

text-decoration: none;

}

input {

font-family: "宋体";

font-size: 12px;

color: #666666;

text-decoration: none;

border: 1px solid #000000;

height: 18px;

}

textarea {

font-family: "宋体";

border: 1px solid #333333;

word-spacing:inherit

}

.table {

font-family: "宋体";

font-size: 12px;

border: 1px solid #000000;

white-space: normal;

table-layout: fixed;

word-break: break-all;

word-wrap: break-word;

display: table;

}

.checkbox {

border: 1px dotted #cccccc;

}

–>

</style>

</head>

<body>

<table width="100%" height="306" border="0" cellpadding="0" cellspacing="0">

<tr>

<td valign="top"><div align="center">

<table width="700" border="0" cellspacing="0" cellpadding="0">

<tr>

<td><div align="center">

<textarea name="inputbox" cols="100" rows="20" id="inputbox"></textarea>

</div></td>

</tr>

</table>

<table width="700" border="0" cellspacing="0" cellpadding="0">

<tr>

<td height="1"></td>

</tr>

</table>

<table width="722" border="0" cellpadding="0" cellspacing="1" class="table">

<tr>

<td height="25" bgcolor="#f2f2f2"><div align="center">正则表达式:

<input name="regexpbox" type="text" id="regexpbox" size="100">

</div></td>

</tr>

</table>

<table width="700" border="0" cellspacing="0" cellpadding="0">

<tr>

<td height="1"></td>

</tr>

</table>

<table width="722" border="0" cellpadding="0" cellspacing="0" class="table">

<tr>

<td width="580" height="25" bgcolor="#f2f2f2"><div align="center">

<input name="singleline" type="checkbox" class="checkbox" value="1">

<span title="将更改(.)的意思,使它包含所有字符">单行模式查找</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<input name="ignorecase" type="checkbox" class="checkbox" value="1">

<span title="不区分字母的大小写">不区分大小写</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<input name="global" type="checkbox" class="checkbox" value="1">

<span title="查找所有的可匹配项">全局模式查找</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<input name="showsub" type="checkbox" class="checkbox" value="1">

<span title="只显示在()里面的记录集">只显示子记录集结果</span>

</div></td>

<td width="140" bgcolor="#f2f2f2"><input name="btnsearch" type="button" id="btnsearch" value="搜 索" onclick="vbscript:searchregexp()"></td>

</tr>

</table>

<table width="700" border="0" cellspacing="0" cellpadding="0">

<tr>

<td height="1"></td>

</tr>

</table>

<table width="722" border="0" cellpadding="0" cellspacing="1" class="table">

<tr>

<td height="25" bgcolor="#ffffcc"><div align="left" id="showtext">

</div></td>

</tr>

</table>

</div></td>

</tr>

</table>

</body>

<script language="vbscript">

function searchregexp()

dim html,ignorecase,global,pattern,showsub

html = document.all.inputbox.value

pattern = document.all.regexpbox.value

if trim(html) = "" or isnull(html) or pattern = "" then

document.all.showtext.innerhtml = "<font color=red>———请输入要查找的文本———</font>"

exit function

end if

if document.all.singleline.checked then

html = replace(html,vbcrlf,"")

end if

global = document.all.global.checked

ignorecase = document.all.ignorecase.checked

showsub = document.all.showsub.checked

dim regexpobj,regmatch,i,ii,submatch

set regexpobj = new regexp

regexpobj.ignorecase = ignorecase

regexpobj.global = global

regexpobj.pattern = pattern

set regmatch = regexpobj.execute(html)

if regmatch.count < 1 then

document.all.showtext.innerhtml = "<font color=red>———共查找到0个记录———</font>"

set regmatch = nothing

set regexpobj = nothing

exit function

end if

document.all.showtext.innerhtml = "<font color=red>———————–查找开始——————–</font><br>"

dim innerhtml

innerhtml = document.all.showtext.innerhtml

for i = 0 to regmatch.count – 1

set submatch = regmatch(i).submatches

if not showsub then

innerhtml = innerhtml + "<font color=red>记录集" & i & ":</font><font color=blue>" + htmlencode(regmatch(i).value) + "</font>"

end if

for ii = 0 to submatch.count – 1

innerhtml = innerhtml + "<br><font color=#ff00ff>" +htmlencode(" 子记录") & ii & ":</font>" + htmlencode(submatch(ii))

next

innerhtml = innerhtml + "<br><hr width=""100%"" size=""1"">"

next

document.all.showtext.innerhtml = innerhtml

set regmatch = nothing

set regexpobj = nothing

end function

function htmlencode(byval fstring)

if not isnull(fstring) then

fstring = replace(fstring, ">", "&gt;")

fstring = replace(fstring, "<", "&lt;")

fstring = replace(fstring, " ", "&nbsp;")

fstring = replace(fstring, chr(32), "<i></i>&nbsp;")

fstring = replace(fstring, chr(9), "&nbsp;")

fstring = replace(fstring, chr(34), "&quot;")

fstring = replace(fstring, chr(39), "&#39;")

fstring = replace(fstring, chr(13), "")

fstring = replace(fstring, chr(10) & chr(10), "</p><p> ")

fstring = replace(fstring, chr(10), "<br> ")

htmlencode = fstring

else

htmlencode=""

end if

end function

</script>

</html>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 正则表达式练习测试页-ASP教程,正则表达式
分享到: 更多 (0)

相关推荐

  • 暂无文章