VBScript正则表达式,用于使用某些附加字符检查IP地址的有效性

VBScript正则表达式,用于使用某些附加字符检查IP地址的有效性,vbscript,Vbscript,如何创建VB脚本不规则表达式语法来检查VPparam(IP地址有效性) 当IP地址的最后一个八位数字在IP(x-y)之间时 在每个IP之间,我们可以放置“,”分隔符,以便添加另一个IP VBparam示例 VBparam=172.17.202.1-20 VBparam=172.17.202.1-10192.9.200.1-100 VBparam=172.17.202.1-10192.9.200.1-100180.1.1.1-20 THX yaelcscript test.vbs 更新:验证IP的

如何创建VB脚本不规则表达式语法来检查VPparam(IP地址有效性) 当IP地址的最后一个八位数字在IP(x-y)之间时 在每个IP之间,我们可以放置“,”分隔符,以便添加另一个IP

VBparam示例

VBparam=172.17.202.1-20

VBparam=172.17.202.1-10192.9.200.1-100

VBparam=172.17.202.1-10192.9.200.1-100180.1.1.1-20

THX yael

cscript test.vbs

更新:验证IP的范围:1-255

更新:固定匹配行的结尾

Dim strByteMatch, strIpMatch, strPattern 
strByteMatch = "(25[0-5]|2[0-4]\d|[01]?\d\d?)"
strIpMatch = strByteMatch & "\." & strByteMatch & "\." & strByteMatch & _
"\.(" & strByteMatch & "|(" & strByteMatch & "-" & strByteMatch & "))"
strPattern = "^" & strIpMatch & "(," & strIpMatch & ")*$"


Test "172.17.202.1-20", strPattern
Test "172.17.202.1-10,192.9.200.1-100", strPattern
Test "172.17.202.1-10,192.9.200.1-100,180.1.1.1-20", strPattern
Test "172.17.202.1bug-20", strPattern            ' This should fail
Test "172.17.202.333,172.17.202.1", strPattern   ' This should fail

Sub Test(strString, strPattern)
    if RegExIsMatch(strString, strPattern) Then
        WScript.Echo "Test Pass"
    else
        WScript.Echo "Test Fail"
    end if
End Sub

Function RegExIsMatch(strString,strPattern)
    Dim RegEx
    RegExMatch=False

    Set RegEx = New RegExp                
    RegEx.IgnoreCase = True                
    RegEx.Global=True                   
    RegEx.Pattern=strPattern

    If RegEx.Test(strString) Then RegExIsMatch=True
End Function 

THX但是我检查了RE,似乎它没有验证IP的范围:1-254,我们可以添加这个规则吗?好的,它的检查可以确定第一个IP,但是如果我们有:172.17.202.1-10192.9.200.1-100180.1.1.1-20 IP,我们如何改进语法来验证第二个或第三个IP??因为它没有检查第二个或其他东西它没有失败:172.17.202.1bug-20(例如)什么?很好你写的,我测试了常规的E和它在所有场景下的工作,谢谢你的帮助yael