Jump to content

StringRegExp Help


Recommended Posts

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

 "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."

Link to comment
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

 "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."

Link to comment
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!"

Link to comment
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"

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!"

Link to comment
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

Link to comment
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.

Link to comment
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!"

Link to comment
Share on other sites

  • Moderators

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...