<HTML>
<HEAD>
<TITLE>笨狼正则练习器_www.jb51.net查字典教程网</TITLE>
<style>
body
{
font-size:12;
BACKGROUND:#DADADA;
margin-left:20;
}
#blockORG
{
font-family:Verdana;
font-size:12px;
overflow:scroll;
height:300;
}
#fileORG
{
width:400;
}
#blockReg
{
font-family:Verdana;
font-size:12px;
}
#showMe
{
font-family:Verdana;
font-size:12px;
height:200;
overflow:visible;
}
#replaceVar
{
font-family:Verdana;
font-size:12px;
top:341;
}
#isScriptDIV
{
position:absolute;
top:361;
overflow-x:visible;
}
</style>
</HEAD>
<BODY>
<INPUTtype="file"id="fileORG"onchange="vbs:showORG"/>
<buttononclick="vbs:showORG">载入</button>
<inputtype="checkbox"id="Imode"checked/>忽略大小写
<inputtype="checkbox"id="Gmode"checked/>全局
<buttononclick="vbs:back">清空</button>
<buttononclick="vbs:saveFile">保存</button><br/>
<textAreaid="blockORG"></textArea><br/>
表达式:<inputid="blockReg"/><br/>
替换为:<inputid="replaceVar"/><inputtype="hidden"id="jsvalue"/>
<divid="isScriptDIV">
<buttonid="normal"onclick="vbs:gogogo">普通替换</button>
<buttonid="isVBS"onclick="vbs:gogogo">vbs表达式替换</button>
<buttonid="isJS"onclick="vbs:gogogo">js表达式替换</button>
</div>
<textAreaid="showMe"></textArea>
<SCRIPTLANGUAGE="vbScript">
'设置窗体尺寸
window.resizeTowindow.screen.availWidth,window.screen.availHeight
window.moveTo0,0
blockORG.style.width=cint(window.screen.availWidth*0.94)
blockReg.style.width=px2Int(blockORG.style.width)-100
replaceVar.style.width=px2Int(blockReg.style.width)-400
isScriptDIV.style.left=px2Int(replaceVar.style.width)+100
showMe.style.width=blockORG.style.width
dimfso,Re
setRe=newRegExp
setfso=createObject("Scripting.FileSystemObject")
dimreplaceStr
dimthisFileDir'定义本文件绝对路径
dimthisFileName'定义本文件名
dimthisFileFolder'定义本文件夹路径
thisFileDir=replace(window.location.href,"file:///","")
thisFileDir=unescape(replace(thisFileDir,"/",""))
thisFileName=LastOne(thisFileDir,"")
thisFileFolder=getFolderDir(thisFileDir)
subshowORG()
'在文本框内加载文件
dimf,ts,s
iffso.FileExists(fileORG.value)then
setf=fso.GetFile(fileORG.value)
setts=f.OpenAsTextStream(1)
s=""
ifnotts.AtEndOfStreamthen
s=ts.ReadAll
endif
ts.Close
blockORG.value=s
endif
endsub
FunctionLastOne(Str,splitStr)
'输入字符和分隔符,得到最后一部分
LastOne=right(Str,len(Str)-InStrRev(Str,splitStr))
EndFunction
functiongetFolderDir(fullDir)
'输入得到全路径,得到文件夹路径
s=LastOne(fullDir,"")
getFolderDir=left(fullDir,len(fullDir)-len(s))
endfunction
functionpx2Int(px)
px2Int=cint(replace(px,"px",""))
endfunction
subgogogo()
Re.IgnoreCase=Imode.checked
Re.Global=Gmode.checked
Re.Pattern=blockReg.value
replaceStr=replaceVar.value
selectcasewindow.event.srcElement.id
case"isVBS"
replaceStr=eval(replaceStr)
case"isJS"
window.execScript"jsvalue.value=eval(replaceVar.value);","javaScript"
replaceStr=jsvalue.value
endselect
showMe.value=Re.Replace(blockORG.value,replaceStr)
endsub
subback
showMe.value=""
endsub
subsaveFile
iffso.FileExists(fileORG.value)then
setf=fso.GetFile(fileORG.value)
f.copyfileORG.value&makeRand()&".bak"'创建备份
setts=f.OpenAsTextStream(2)
ts.writeshowMe.value
ts.Close
blockORG.value=showMe.value
else
setts=fso.OpenTextFile(thisFileFolder&makeRand()&".txt",2,true)
ts.writeshowMe.value
ts.Close
blockORG.value=showMe.value
endif
endsub
functionmakeRand()
dimresault
resault=mid(cstr(now()),3)
resault=replace(resault,":","")
resault=replace(resault,"-","")
resault=replace(resault,"","")
makeRand=resault
endfunction
</SCRIPT>
</BODY>
</HTML>
笨狼正则练习器.hta