正则表达式 <script language="vbScript" > set re = new RegExp re.Pattern = "[-:\s]" re.Global = true msgbox re.Replace(now(), "") set re =nothing </script>
Function IsVerify(patrn,strng) strng=Trim(strng) Select Case patrn Case "User" '用户名 patrn="^[a-z]{1}([a-z0-9]|[._]){2,19}$" Case "Truename" '英文姓名 patrn="^[a-zA-Z]{1,30}$" Case "Passwd" '密码 patrn="^(\w){6,20}$" Case "Tel" '电话/传真 patrn="^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$" Case "Mobil" '手机 patrn="^(\d)+[-]?(\d){6,12}$" Case "Date" '日期(格式:yyyy-mm-dd) patrn="^[12]{1}(\d){3}[-][01]?(\d){1}[-][0123]?(\d){1}$" Case "Email" '电子邮件 patrn="^((\w)|[-]|[.])+@(((\w)|[-])+[.])+[a-z]{2,4}$" Case "Postalcode" '邮政编码 patrn="^[a-z0-9 ]{3,12}$" Case "Search" '搜索关键字 patrn="^[^`~!@#$%^&*()+=|\\\[\]\{\}:;\'\,.<>/?]{1}[^`~!@$%^&()+=|\\\[\]\{\}:;\'\,.<>?]{0,19}$" Case "Int" '整数 patrn="^[1-9]{1}[0-9]{0,5}$" Case "Array" patrn="^[0-9]{1}([0-9]|[\,]){0,150}$" End Select Dim regEx Dim Match Set regEx = New RegExp regEx.Pattern = patrn regEx.IgnoreCase = True regEx.Global = True Matches = regEx.test(strng) IsVerify = Matches Set regEx = Nothing End Function
<SCRIPT LANGUAGE=vbs> a="A1B2C3" Function F(S,P) Dim regEx, Match, Matches ' 建立变量。 Set regEx = New RegExp ' 建立正则表达式。 regEx.Pattern = P ' 设置模式。 regEx.IgnoreCase = True ' 设置是否区分字符大小写。 regEx.Global = True ' 设置全局可用性。 Set Matches = regEx.Execute(S) ' 执行搜索。 For Each Match in Matches ' 遍历匹配集合。 S =replace(S,Match.Value,"") Next F = S End Function MsgBox F(a,"\d") </SCRIPT>
求一个正则表达式的模式字符串,匹配下列字符串 href="http://www.csdn.net/abc.jpg" 就是匹配以href=开头,.jpg或者.gif,.bmp,.png等图片扩展名结束的字符
但是下面的情况不可以匹配: href=imageView.asp?abc.jpg,就是说字符中含有.asp,.php,.jsp等不匹配
具体来说就是一个html格式的字符串,里面有一些链接点击后显示图片,现在要把这些链接替换成ASP页面(imageView.asp),然后页面中显示图片,图片的url用imageView.asp?url=abc.jpg这样的参数传递到imageView.asp
'=================================================== '函数名:replaceImageView '作 用:把图片链接替换成网页链接,网页中显示图片 '参 数:strContent ----------- 要替换的html字符串 '=================================================== function replaceImageView( strContent ) Set re = new RegExp re.IgnoreCase = True re.Global = True re.Pattern = "(href=)(S*)((\w)+[.]{1}(jpg|jpeg|gif|bmp|png))" Set imageLink = re.Execute( strContent ) i = 1 for each imageLinkUrl in imageLink tempUrl = Replace( imageLinkUrl, "href=", "") tempUrl = Replace( tempUrl, """", "" ) strContent = Replace( strContent, tempUrl, "imageView.asp?url="+tempUrl ) next replaceImageView = strContent end function
a = a.replace(/(^[\s]*)|([\s]*$)/g, ""); 
|