Moze Posted September 16, 2007 Share Posted September 16, 2007 (edited) Hello i'm kinda noob at programing and trying to make function that will check if string is valid IP address. i use StringRegExp. At moment pattern that i wrote is: StringRegExp("192.168.1.1", '\A[1-255]\.[0-255]\.[0-255]\.[0-255]\z', 0) But it does not work. Please help me to make a good pattern that will match a valid ip address. P.S. English isn't my native language... Edited September 16, 2007 by Moze Link to comment Share on other sites More sharing options...
weaponx Posted September 16, 2007 Share Posted September 16, 2007 There is an example of this on the regular-expressions.info example page:http://www.regular-expressions.info/examples.html Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 16, 2007 Moderators Share Posted September 16, 2007 http://www.autoitscript.com/forum/index.ph...c=39932&hl= Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Moze Posted September 16, 2007 Author Share Posted September 16, 2007 Thankyou for replay Link to comment Share on other sites More sharing options...
weaponx Posted September 16, 2007 Share Posted September 16, 2007 (edited) You could also say "Screw regular expressions!":$testip = "300.50.50.50" MsgBox(0,"",validIP($testIP)) ;Return 0 if valid ;Return 1 if ip has too many or too few bytes ;Return 2 if any byte is out of range Func validIP($ip) $ipArray = StringSplit($ip,".") If $ipArray[0] <> 4 Then Return(1) EndIf For $X = 1 to 4 If $ipArray[$X] < 0 OR $ipArray[$X] > 255 Then Return(2) EndIf Next Return(0) EndFunc Edited September 17, 2007 by weaponx Link to comment Share on other sites More sharing options...
Moze Posted September 17, 2007 Author Share Posted September 17, 2007 Thx weaponx i came with same solution Link to comment Share on other sites More sharing options...
enaiman Posted September 18, 2007 Share Posted September 18, 2007 Minor correction on weaponx script: The first part of an IP address can't be 0 while any other can be, so the script need to be just a little "tuned" for $ipArray [1] which needs to be >0 and <255 SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now