tags:

views:

33

answers:

1

How to create VB script Irregular expression syntax to check the VPparam (IP address validity) When the last octatat of the IP address is a range between ip's (x-y) and between each IP we can put the "," separator in order to add another IP

example of VBparam

VBparam=172.17.202.1-20

VBparam=172.17.202.1-10,192.9.200.1-100

VBparam=172.17.202.1-10,192.9.200.1-100,180.1.1.1-20

THX yael

A: 

I believe the term you're looking for is "regular expression", not "irregular" - might help when google searching. I don't know enough VB to provide a complete script, but the pattern you're looking for is:
(\d{1,3}\.){3}\d{1,3}(\-\d{1,3})?(,(\d{1,3}\.){3}\d{1,3}(\-\d{1,3})?)*

This will not validate that X < Y, or that each octet is in a proper range, i.e. 999.999.999.999 would be valid. You can't validate X < Y in regex (abbrev. for regular expression), so you'll need to use pattern captures to validate those yourself in the script. If you wish to validate that octets are in the proper range, replace \d{1,3} with ((1\d{2})|(2[0-4]\d)|(25[0-5])|\d{1,2}) each time it appears in the above script.

Darth Android
hi again I replace the \d{1,3} with the rest syntax but its not work need somthing else to add?Dim strPattern: strPattern= "(((1\d{2})|(2[0-4]\d)|(25[0-5])|\d{1,2})((1\d{2})|(2[0-4]\d)|(25[0-5])|\d{1,2})\.){3}((1\d{2})|(2[0-4]\d)|(25[0-5])|\d{1,2})(\-((1\d{2})|(2[0-4]\d)|(25[0-5])|\d{1,2}))?(,(((1\d{2})|(2[0-4]\d)|(25[0-5])|\d{1,2})\.){3}((1\d{2})|(2[0-4]\d)|(25[0-5])|\d{1,2})(\-)?)*"
@yael I just tested it with the examples you provided, and the expression works. Keep in mind that `\ ` is often an escape character in languages, it might have to be escaped in VBscript. Such fully-escape expression would be `(((1\\d{2})|(2[0-4]\\d)|(25[0-5])|\\d{1,2})\\.){3}((1\\d{2})|(2[0-4]\\d)|(25[0-5])|\\d{1,2})(\\-((1\\d{2})|(2[0-4]\\d)|(25[0-5])|\\d{1,2}))?(,(((1\\d{2})|(2[0-4]\\d)|(25[0-5])|\\d{1,2})\\.){3}((1\\d{2})|(2[0-4]\\d)|(25[0-5])|\\d{1,2})(\\-((1\\d{2})|(2[0-4]\\d)|(25[0-5])|\\d{1,2}))?)*`
Darth Android
OK thx I will keep in mindyael