标签归档:regExp

Javascript 电话匹配脚本

最近朋友让帮忙写个电话匹配脚本。能支持的电话有手机号,电话号码。手机号、电话区号前面均可带零。

<pre><script type="text/javascript">
var $ = {
'blue':'<span style=color:#090>[OK]</span>',
'red':'<span style=color:#FAA>Bad.</span>'
}
var ttt = Array(
'+86.053912345678',
'015854999261',
'15854999261',
'158549992161',
'+86.5391234567'
);
for(i=0;i<ttt.length;i++){
  document.writeln(ttt[i] + "\t: " + $[(ttt[i].match(/^(\+86\.0?\d{10,11}|(015|013|15|13)\d{9})$/ig)?"blue":"red")]);
}
</script>

用ASP/VBScript获取文章列表

< %
'ASP获取文章列表
function getHTTPPage(url)  
	dim Http  
	set Http=server.createobject("MSXML2.XMLHTTP")  
	Http.open "GET",url,false  
	Http.send()  
	if Http.readystate<>4 then  
		exit function  
	end if  
	getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")  
	set http=nothing  
	if err.number<>0 then err.Clear  
end function  
 
Function BytesToBstr(body,Cset)  
	dim objstream  
	set objstream = Server.CreateObject("adodb.stream")  
	objstream.Type = 1  
	objstream.Mode =3  
	objstream.Open  
	objstream.Write body  
	objstream.Position = 0  
	objstream.Type = 2  
	objstream.Charset = Cset  
	BytesToBstr = objstream.ReadText  
	objstream.Close  
	set objstream = nothing  
End Function  
 
Function ZZ(ustr,uexp)
	Set regEx=New RegExp
	regEx.Pattern=uexp
	regEx.IgnoreCase=True
	regEx.Global=True
	Set ZZ=regEx.Execute(ustr)
End Function
 
Sub Echo(t)
	response.write t&"<br />"&vbcrlf
End Sub
 
Sub getall(url,xurl,uri)
	Html = getHTTPPage(uri&Url)
	set Rs=ZZ(html,"("&xurl&"?.*)[#""].*>(.*)< \/a")
	for each uurl in Rs
		'echo uri&replace(uurl,"""","")
		Set oMacs=uurl
		echo uri&oMacs.SubMatches(0)&"|"&oMacs.SubMatches(1)
	next
End Sub
 
urls=split("ftgb|ftlg|zykt","|")
xurls=split("ftgbxx|ftlgxx|zyktcpxx","|")
for i=0 to ubound(urls)
	getall urls(i)&".jsp",xurls(i)&".jsp","http://gree.com.cn/gree_product/"
next
%>

下边发个VBscript版本的

'VBScript获取文章列表
function getHTTPPage(url)  
	dim Http  
	set Http=createobject("MSXML2.XMLHTTP")  
	Http.open "GET",url,false  
	Http.send()  
	if Http.readystate<>4 then  
		exit function  
	end if  
	getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")  
	set http=nothing  
	if err.number<>0 then err.Clear  
end function  
 
Function BytesToBstr(body,Cset)  
	dim objstream  
	set objstream = CreateObject("adodb.stream")  
	objstream.Type = 1  
	objstream.Mode =3  
	objstream.Open  
	objstream.Write body  
	objstream.Position = 0  
	objstream.Type = 2  
	objstream.Charset = Cset  
	BytesToBstr = objstream.ReadText  
	objstream.Close  
	set objstream = nothing  
End Function 
 
Function ZZ(ustr,uexp)
	Set regEx=New RegExp
	regEx.Pattern=uexp
	regEx.IgnoreCase=True
	regEx.Global=True
	Set ZZ=regEx.Execute(ustr)
End Function
 
Sub Echo(t)
	Wscript.echo t
End Sub
 
Sub getall(url,xurl,uri)
	Html = getHTTPPage(uri&Url)
	set Rs=ZZ(html,"("&xurl&"?.*)[#""].*>(.*)< \/a")
	for each uurl in Rs
		'echo uri&replace(uurl,"""","")
		Set oMacs=uurl
		echo uri&oMacs.SubMatches(0)&"|"&oMacs.SubMatches(1)
	next
End Sub
 
urls=split("ftgb|ftlg|zykt","|")
xurls=split("ftgbxx|ftlgxx|zyktcpxx","|")
for i=0 to ubound(urls)
	getall urls(i)&".jsp",xurls(i)&".jsp","http://gree.com.cn/gree_product/"
next

用到了正则表达式,令以前收藏的一个正则表达式教程分享给代价