欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

正则表达式在线测试工具

程序员文章站 2023-08-26 20:54:26
复制代码 代码如下:
复制代码 代码如下:

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-cn">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<meta http-equiv="content-language" content="zh-cn" />
<meta name="author" content="wangorg(at)gmail.com,梦迟" />
<meta name="copyright" content="mengchi.cn,转载请注明出处,作者梦迟原创。" />
<meta name="description" content="闲来无事,做了个测试正则表达式的工具,转载请注明出处." />
<meta content="梦迟,在线测试,正则表达式,mengchi,正则,工具" />
<title>在线测试正则表达式工具-梦迟出品</title>
<script type="text/javascript">
function mengchi(){
var a=document.getelementbyid("mc1").value;
var b=document.getelementbyid("mc2").value;
var c=new regexp(a,"g");
     document.getelementbyid("mc3").value="";
     pipei.innerhtml="匹配结果:0";
var arrmactches = b.match(c);
     for (var i=0;i < arrmactches.length ; i++){
         if (a!=""){
             ee=document.getelementbyid("mc3").value+"\n"+arrmactches[i];
             document.getelementbyid("mc3").value=ee;
             pipei.innerhtml="匹配结果:"+(i+1);
         }
     }
document.getelementbyid("mc3").value=document.getelementbyid("mc3").value.replace("\r\n","");
}
function charu (text) {
    document.all.mc1.focus();
        event.srcelement.document.selection.createrange().text += text;
    document.all.mc1.blur();
}
function qingchu () {
    document.getelementbyid("mc1").value="";
}
</script>
</head>
<!--body部代码开始,作者梦迟(mengchi.cn)转载请注明出处-->
<body>
<p>正则表达式:</p>
<p>
<input name="mc1" type="text" id="mc1" size="88" onblur="mengchi();"/>
</p>
<p>
<input type="button" value="^" onclick="charu('^');">
<input type="button" value="[" onclick="charu('[');">
<input type="button" value="a-z" onclick="charu('a-z');">
<input type="button" value="0-9" onclick="charu('0-9');">
<input type="button" value="]" onclick="charu(']');">
<input type="button" value="+" onclick="charu('+');">
<input type="button" value="*" onclick="charu('*');">
<input type="button" value="?" onclick="charu('?');">
<input type="button" value="." onclick="charu('.');">
<input type="button" value="\" onclick="charu('\\');">
<input type="button" value="w" onclick="charu('w');">
<input type="button" value="b" onclick="charu('b');">
<input type="button" value="d" onclick="charu('d');">
<input type="button" value="f" onclick="charu('f');">
<input type="button" value="n" onclick="charu('n');">
<input type="button" value="{" onclick="charu('{');">
<input type="button" value="," onclick="charu(',');">
<input type="button" value="}" onclick="charu('}');">
<input type="button" value="$" onclick="charu('$');">
<input type="button" value="清除" onclick="qingchu();">
</p>
<p>处理数据:</p>
<p>
<textarea name="mc2" cols="88" rows="10" id="mc2" onblur="mengchi();"></textarea>
</p>
<p>处理结果:</p>
<p>
<textarea name="mc3" cols="88" rows="10" id="mc3" onblur="mengchi();"></textarea>
</p>
<p>
<span id="pipei"></span>
</p>
</body>
</html>

在线测试  
在线工具2