Sign in to follow this  
Followers 0
ken82m

StringRegExp Help

11 posts in this topic

I suck at this can someone please help me with this.

I just want to check the format of something to see if it is a properly formatted IP address.

so it should be xxx.xxx.xxx

each x has to be a number

and each section can be 1-3 numbers

Here's my poor attempt lol

$1 = "1.1.1.1"
$1 = StringRegExp("1.1.1.1", "[:digit:]/x00")
MsgBox(0,"is ip", $1)

Thanks,

Kenny


My Contributions _StringMultiReplace PC Builders Console - Secure PDF Creator - Cisco VPN Installer MS DNS Server Backup Script - MS DHCP Backup Script IT Admin Console - Toggle Admin Mode - MyMovies-Add Discs Script - IT Help Desk and System Information Tool - Set On Lid Close Power Option - Streaming Media Server & Website "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

http://www.regextester.com/

Check the list on the bottom, some nice patterns for known decimal inputs like IPv4 etc..

Edit: I see it's IPv4 pattern is broken so here it's anyway, fail faster in my opinion:

^(?>(?:\d|[01]?\d\d|25[0-5]|2[0-4]\d)\.){3}(?:\d|[01]?\d\d|25[0-5]|2[0-4]\d)$'
Edited by Authenticity

Share this post


Link to post
Share on other sites

thanks for the string, and the site.

Wouldn't happen to know one to help me build one would you? :P


My Contributions _StringMultiReplace PC Builders Console - Secure PDF Creator - Cisco VPN Installer MS DNS Server Backup Script - MS DHCP Backup Script IT Admin Console - Toggle Admin Mode - MyMovies-Add Discs Script - IT Help Desk and System Information Tool - Set On Lid Close Power Option - Streaming Media Server & Website "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Share this post


Link to post
Share on other sites

Here is another regexp that I think will do what you want. I could be wrong though. That happened once before.

"(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

It can match for sure, anything from "0.0.0.0somthinglong" to "999.999.999.999Somethingevenlonger...0.0.0.999999999and this"

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

It can match for sure, anything from "0.0.0.0somthinglong" to "999.999.999.999Somethingevenlonger...0.0.0.999999999and this"

That makes twice now (that I've been wrong).

Edit. Oooops, forgot to mention that I was talking about twice within a 3 minute time span.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

GEOSoft, technically you're correct in looking for 4 1-3-digit pairs, but if you need to make sure it doesn't include any other characters in the string, you can just add the start-of-string and end-of-string characters to each side like this:

^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$

Of course, they are right about invalid IP addresses.. I really don't know the correct range of #'s myself

Share this post


Link to post
Share on other sites

You don't need to care if this IP address exists as you may want to make sure it's first in the range 0-255 in all the fields, it's also true that 0.0.0.0 certainly does not exist as 255.255.255.255 for that matter neither. The rest of the check is using a data base or calling ping.

Share this post


Link to post
Share on other sites

It actually could be handled with a stringsplit too. Then just check that the number in each element is between 0 and 255. SmOke_Ns solution works. Just difficult to read with the AutoIt tags and smileys enabled.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

This should work as well, not much different I'm sure from what I've posted before in the link provided:

Local $s_text = ClipGet()

Local $s_pattern = "((?:(?:[0-1][0-9]{2}|2[0-4][0-9]|25[0-5]|[0-9]){1,2}\.){3}" & _
                    "(?:[0-1][0-9]{2}|2[0-4][0-9]|25[0-5]|[0-9]))"

Local $a_sre = StringRegExp($s_text, $s_pattern, 3)

Edited by SmOke_N

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.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0