常用的正则表达式集合

正则表达式
  
  正则表达式 正则表达式

  <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),然后页面中 显示图片,图片的urlimageView.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, "");

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值