'只能输入数字0-9
'msgbox (IsRegMatch("^[0-9]*$","12q34"))
'不包含&字符号
'msgbox "&& "&IsRegMatch("^[^&]*$","12&q34")
'只包含0-9ABCD*#
'msgbox "1 "&IsRegMatch("^[0-9ABCD*#]*$","1234")
'msgbox "* "&IsRegMatch("^[0-9ABCD*#]*$","1*34")
'msgbox "*# "&IsRegMatch("^[0-9ABCD*#]*$","12*#34")
'msgbox "A "&IsRegMatch("^[0-9ABCD*#]*$","12*#AB34")
'msgbox "C "&IsRegMatch("^[0-9ABCD*#]*$","12*#C34")
'msgbox "&5454& "&IsRegMatch("^[0-9ABCD*#]*$","12*#C$34678")
'msgbox "&& "&IsRegMatch("^[0-9ABCD*#]*$","-12*#C34")
'msgbox "&& "&IsRegMatch("^[0-9ABCD*#]*$","12*#C)34")
'3月22日 ==》 ^([1-9]|1[0-2])[月]([1-9]|[12]\d{1}|3[01])[日]$
'msgbox "&& "&IsRegMatch("^([1-9]|1[0-2])[月]([1-9]|[12]\d{1}|3[01])[日]$","12e月12日")
'msgbox "22 "&IsRegMatch("^([1-9]|1[0-2])[月]([1-9]|[12]\d{1}|3[01])[日]$","12月12日")
'msgbox "33 "&IsRegMatch("^([1-9]|1[0-2])[月]([1-9]|[12]\d{1}|3[01])[日]$","13月12日")
'msgbox "44 "&IsRegMatch("^([1-9]|1[0-2])[月]([1-9]|[12]\d{1}|3[01])[日]$","12月32日")
'msgbox "54 "&IsRegMatch("^([1-9]|1[0-2])[月]([1-9]|[12]\d{1}|3[01])[日]$","12月0日")
'msgbox "66 "&IsRegMatch("^([1-9]|1[0-2])[月]([1-9]|[12]\d{1}|3[01])[日]$","0月1日")
'msgbox "76 "&IsRegMatch("^([1-9]|1[0-2])[月]([1-9]|[12]\d{1}|3[01])[日]$","1月1日")
'判断正则匹配是否正确
Function IsRegMatch(patrn,str)
Dim regEx
Set regEx = New RegExp
regEx.Pattern = patrn
regEx.IgnoreCase = False
IsRegMatch = regEx.Test(str)
Set regEx = nothing
End Function
'msgbox (ReplaceRegMatch("9","loader runner 9.0, qtp 9.0","10"))
'替换匹配字符串
Function ReplaceRegMatch(patrn,str,replaceStr)
Dim regEx
Set regEx = New RegExp
regEx.Pattern = patrn
regEx.IgnoreCase = False
regEx.Global = True 'false的时候只会替换第一个匹配的字符串。若为true则会替换所有匹配的字符串
ReplaceRegMatch = regEx.Replace(str,replaceStr)
End Function
'returnRegMatch "qtp .","qtp 1 qtp 2 qtp3 qtp 4"
'返回匹配内容
Function ReturnRegMatch(patrn,str)
Dim regEx,matches,match
Set regEx = New RegExp
regEx.Pattern = patrn
regEx.IgnoreCase = true
regEx.Global = true '打开全局搜索
Set matches = regEx.Execute(str)
For Each match in matches
print cstr(match.firstIndex) + " " + match.value + " " + cstr(match.length)
Next
End Function
'GetIPAddrValue("10.100.20.168")
'取得IP地址的值(即将点转换成整个数字)
Function GetIPAddrValue (ip)
Dim bTemp
bTemp = false
'Split(MyString, "x", -1, 1)
ip=Split(ip,".",-1,1)
bTemp = ip(0)*255*255*255+ip(1)*255*255+ip(2)*255+ip(3)*1
msgbox "IP值是:"&(bTemp)
End Function
'msgbox "IP " &IsRegMatchIPAddr("^(\d+)\.(\d+)\.(\d+)\.(\d+)$","104.1.0.275")
'判断IP地址是否正确
Function IsRegMatchIPAddr(patrn,ip)
Dim regEx
Set regEx = New RegExp
regEx.Pattern = patrn
regEx.IgnoreCase = False
if( regEx.Test(ip)) then
ip=Split(ip,".",-1,1)
For i = 0 To 3 step 1
if( ip(i) < 0 or ip(i) > 255 ) then
IsRegMatchIPAddr=false
set regEx = nothing
Exit function
End if
Next
IsRegMatchIPAddr = true
set regEx = nothing
Exit function
End if
IsRegMatchIPAddr = false
set regEx = nothing
End Function
Function SplitsStr(str, char)
SplitsStr=Split(str,char,-1,1)
End Function