在ASP中使用正则表达式
Dim arr
arr = regExec("192.168.a.1", "(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]{2}|[1-9])\.")
Response.Write Ubound(arr)&"<br><br>"
Set re = New RegExp
re.Pattern = p
re.IgnoreCase = true
re.Global = true
regTest = re.Test(str)
End Function
Function regReplace(ByVal str, p, str2)
If emp(str) Then
regReplace = ""
Else
Dim re
Set re = New RegExp
re.IgnoreCase = true
re.Global = true
re.Pattern = p
regReplace = re.Replace(str, str2)
End If
End Function
Function regMatch(Str, Pattern)
Dim regEx, obj
Set regEx = New RegExp
regEx.Pattern = Pattern
regEx.IgnoreCase = True
regEx.Global=True
Set obj = regEx.Execute(Str)
If obj.Count=0 Then
regMatch= array()
Else
Dim arr(), result, i
Redim arr(obj.count-1)
i=0
For Each result In obj
arr(i)=result
i=i+1
Next
regMatch=arr
End If
End Function
arr = regExec("192.168.a.1", "(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]{2}|[1-9])\.")
Response.Write Ubound(arr)&"<br><br>"
Response.Write regReplace("[IMG]http://www.baidu.com/img/baidu_sylogo1.gif[/IMG]", "\[IMG\](.+)\[\/IMG\]", "<img src=""$1"" />")
Function regTest(ByVal str, p) Dim reSet re = New RegExp
re.Pattern = p
re.IgnoreCase = true
re.Global = true
regTest = re.Test(str)
End Function
Function regReplace(ByVal str, p, str2)
If emp(str) Then
regReplace = ""
Else
Dim re
Set re = New RegExp
re.IgnoreCase = true
re.Global = true
re.Pattern = p
regReplace = re.Replace(str, str2)
End If
End Function
Function regMatch(Str, Pattern)
Dim regEx, obj
Set regEx = New RegExp
regEx.Pattern = Pattern
regEx.IgnoreCase = True
regEx.Global=True
Set obj = regEx.Execute(Str)
If obj.Count=0 Then
regMatch= array()
Else
Dim arr(), result, i
Redim arr(obj.count-1)
i=0
For Each result In obj
arr(i)=result
i=i+1
Next
regMatch=arr
End If
End Function