vbscript里匹配
1<input ...=""/>
1<select ...="">...</select>
1<textarea ...="">...</textarea>
这些正则表达式该怎么些
---------------------------------------------------------------
1<input id="oText" value="00100100.1"/>
1<input onclick="window.alert(parseFloat(self['oText'].value));" type="button" value="测试"/>
---------------------------------------------------------------
"^\\d+$" //非负整数(正整数 + 0)
"^[0-9][1-9][0-9]$" //正整数
"^((-\\d+) ¦(0+))$" //非正整数(负整数 + 0)
"^-[0-9][1-9][0-9]$" //负整数
"^-?\\d+$" //整数
"^\\d+(\\.\\d+)?$" //非负浮点数(正浮点数 + 0)
"^(([0-9]+\\.[0-9][1-9][0-9]) ¦([0-9][1-9][0-9]\\.[0-9]+) ¦([0-9][1-9][0-9]))$" //正浮点数
"^((-\\d+(\\.\\d+)?) ¦(0+(\\.0+)?))$" //非正浮点数(负浮点数 + 0)
"^(-(([0-9]+\\.[0-9][1-9][0-9]) ¦([0-9][1-9][0-9]\\.[0-9]+) ¦([0-9][1-9][0-9])))$" //负浮点数
"^(-?\\d+)(\\.\\d+)?$" //浮点数
"^[A-Za-z]+$" //由26个英文字母组成的字符串
"^[A-Z]+$" //由26个英文字母的大写组成的字符串
"^[a-z]+$" //由26个英文字母的小写组成的字符串
"^[A-Za-z0-9]+$" //由数字和26个英文字母组成的字符串
"^\\w+$" //由数字、26个英文字母或者下划线组成的字符串
"^[\\w-]+(\\.[\\w-]+)@[\\w-]+(\\.[\\w-]+)+$" //email地址
"^[a-zA-z]+://(\\w+(-\\w+))(\\.(\\w+(-\\w+)))(\?\\S*)?$" //url
---------------------------------------------------------------
1<html>
2<head>
3<title>正则表达式练习器</title>
4<meta e-mail:[email protected]="" name="安徽" 徐祖宁="" 池州="" 统计局=""/>
5<script language="JavaScript">
6function OnMove() {
7window.status = "("+window.event.clientX+","+window.event.clientY+")" + " :: "+document.location
8}
9</script>
10<script language="JavaScript1.2">
11var re = new RegExp() //建立正则表达式对象
12var nextpoint = 0 //匹配时的偏移量
13//设置正则表达式
14function setPattern(form) {
15var mode
16if(form.chkmode.checked) mode = "gi" //i:不分大小写 g:全局,好象没什么作用
17else mode = "g"
18re.compile(form.regexp.value,mode)
19nextpoint = 0
20form.reglist.value = ""
21}
22//检查是否有匹配
23function findIt(form) {
24setPattern(form)
25var input = form.main.value
26if (input.search(re) != -1) {
27form.output[0].checked = true
28} else {
29form.output[1].checked = true
30}
31}
32//检查匹配位置
33function locateIt(form) {
34setPattern(form)
35var input = form.main.value
36form.offset.value = input.search(re)
37}
38//检查所有的匹配情况
39function execIt(form) {
40if(nextpoint == 0 ¦ ¦ ! form.scankmode.checked) {
41findIt(form)
42form.reglist.value = ""
43}
44var key = true
45if(form.scankmode.checked) key = false
46do {
47var input = form.main.value
48var matchArray = re.exec(input.substr(nextpoint))
49if(matchArray) {
50for(var i=1;i<matchArray.length;i++)
51matchArray[i] = "$"+i+":"+matchArray[i]
52form.reglist.value = (nextpoint+matchArray.index)+" => " + matchArray[0] +"\n"+form.reglist.value
53form.matchlist.value = "$0:"+matchArray.join("\n")
54nextpoint = nextpoint + matchArray.index + matchArray[0].length
55}else {
56if(!key)
57form.reglist.value = "没有找到\n" + form.reglist.value
58form.matchlist.value = " "
59nextpoint = 0
60key = false
61}
62}while (key)
63}
64//设置当前使用的正则表达式
65function setregexp(n) {
66var s = document.all.regexplist.value.split("\r\n")
67document.all.regexp.value = s[n*2-1] //.replace("\r","")
68nextpoint = 0
69}
70
71//定义选择监视
72var isNav = (navigator.appName == "Netscape")
73function showSelection() {
74if (isNav) {
75var theText = document.getSelection()
76} else {
77var theText = document.selection.createRange().text
78}
79if(theText.length>0 && document.all.selechkmode.checked)
80document.all.regexp.value = theText
81}
82if (isNav) {
83document.captureEvents(Event.MOUSEUP)
84}
85document.onmouseup = showSelection
86</script>
87</head>
88<body onmousemove="OnMove()" style="font-size=9pt;">
89<form><table cellpadding="0" cellspacing="0" width="100%"><tr><td><font color="red">正规表达式练习器</font></td><td align="right"><a href="mailto:[email protected]">[email protected]</a></td></tr></table>
90<table broder="1" frame="above" rules="none" style="font-size:9pt;" width="100%">
91<tr><td valign="top" width="50%">
92输入一些被寻找的正文:<br/>
93<textarea cols="58" name="main" rows="5" style="font-size:9pt;" wrap="virtual">
9409-11-2001 09/11/2001 [email protected]
95asdff 12345 196.168.1.3 www.sohu.com ftp://www.chinaasp.com 2001.9.11 http://www.active.com.cn/club/bbs/bbsView.asp http://www.163.com/inden.htm
96</textarea><br/>
97进行匹配的正规表达式: 忽略大小写<input checked="" name="chkmode" style="font-size:8pt;height:18px" type="checkbox"/><br/>
98<textarea cols="51" name="regexp" rows="5" style="font-size:9pt;"></textarea>
99<input onclick="this.form.regexp.value=''" style="font-size:8pt;height:18px" type="button" value="清除"/><br/>
100<input onclick="findIt(this.form)" style="font-size:8pt;width:70%;height:18px" type="button" value="能找到吗?[regexObject.test(string)]"/>
101<input name="output" style="font-size:8pt;height:18px" type="radio"/>Yes
102<input name="output" style="font-size:8pt;height:18px" type="radio"/>No <br/>
103<input onclick="locateIt(this.form)" style="font-size:8pt;width:70%;height:18px" type="button" value="在哪里?[string.search(regexObject)]"/>
104<input name="offset" size="4" style="font-size:8pt;height:18px" type="text"/>
105</td>
106<td valign="top">
107测试用正则表达式列表:
108使用第<input name="num" size="2" style="font-size:8pt;height:18px" type="text" value="1"/>个<input onclick="setregexp(this.form.num.value)" style="font-size:8pt;height:18px" type="button" value="Go"/>
109允许复制<input name="selechkmode" style="font-size:8pt;height:18px" type="checkbox"/>
110<textarea cols="58" name="regexplist" rows="14" style="font-size:9pt;" wrap="off">
1111.检查日期:
112(1[0-2] &brvbar0?[1-9])[-./](0?[1-9] ¦[12][0-9] &brvbar3[01])[-./](\d\d\d\d))
1132.检查数字:
114([-+]?[0-9]+\\.?[0-9]+)
1153.检查URL:
116((http &brvbarftp)://)?(((([\d]+\\.)+){3}[\d]+(/[\w./]+)?) ¦([a-z]\w*((\\.\w+)+){2,})([/][\w.~]*)*)
1174.检查E-mail
118\w+@((\w+[.]?)+)
119</textarea>
120</td></tr>
121<tr><td valign="bottom">
122<input onclick="execIt(this.form)" style="font-size:8pt;width:70%;height:18px" type="button" value="有哪些?[regexObject.exec(string)]"/>
123单步<input name="scankmode" style="font-size:8pt;height:18px" type="checkbox"/><br/>
124<textarea cols="58" name="reglist" rows="8" style="font-size:9pt;"></textarea>
125</td>
126<td valign="bottom">
127匹配到的成分:(单步时可见)
128<textarea cols="58" name="matchlist" rows="8" style="font-size:9pt;"></textarea>
129</td></tr></table></form>
130<script>
131setregexp(1)
132</script>
133</body>
134</html>