SpinningCone Posted January 12, 2009 Share Posted January 12, 2009 I'm trying to get my regex to return true if the string is *only* numeric and at least 3 digits long I was using StringRegExp($sTemp, "[0-9]{3}") but it will return true for things like "junk1234junk" I cant seem to figure out how to do a "and must not contain [a-z]" type regex. i tried [^:alpha:] but that still just matches numbers and "junk1234junk" is positive. Any help would be appreciated. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 12, 2009 Moderators Share Posted January 12, 2009 I'm trying to get my regex to return true if the string is *only* numeric and at least 3 digits long I was using StringRegExp($sTemp, "[0-9]{3}") but it will return true for things like "junk1234junk" I cant seem to figure out how to do a "and must not contain [a-z]" type regex. i tried [^:alpha:] but that still just matches numbers and "junk1234junk" is positive. Any help would be appreciated.^ or /A for the beginning of the string $ or \z for the end of the string Expression would be something like: "^\d{3}$" or "\A\d{3}\z" etc... 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...
SpinningCone Posted January 12, 2009 Author Share Posted January 12, 2009 (edited) ^ or /A for the beginning of the string $ or \z for the end of the string Expression would be something like: "^\d{3}$" or "\A\d{3}\z" etc... neither of those work they fail to find a number. after i posted a methood did occur to me its not optimal i would still rather have one regex but it works if not StringRegExp($sTemp, "[\D]") then If StringRegExp($sTemp, "[0-9]{3}") then My code endif endif Edited January 12, 2009 by SpinningCone Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 12, 2009 Moderators Share Posted January 12, 2009 (edited) neither of those work they fail to find a number. after i posted a methood did occur to me its not optimal i would still rather have one regex but it works if not StringRegExp($sTemp, "[\D]") then If StringRegExp($sTemp, "[0-9]{3}") then My code endif endifYou don't seem to be doing what I suggested:Local $a_sample[4] = ["junk1234junk","123","1234","j12"] For $i = 0 To UBound($a_sample) - 1 If StringRegExp($a_sample[$i], "^\d{3}$") Then MsgBox(64, "Info", "Array Element " & $i & " is true." & @CRLF & $a_sample[$i]) EndIf Next Edit: I misread the at least part. Try this:Local $a_sample[4] = ["junk1234junk","123","1234","j12"] For $i = 0 To UBound($a_sample) - 1 If StringRegExp($a_sample[$i], "^\d\d\d+$") Then MsgBox(64, "Info", "Array Element " & $i & " is true." & @CRLF & $a_sample[$i]) EndIf Next Edited January 12, 2009 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 More sharing options...
Xenobiologist Posted January 12, 2009 Share Posted January 12, 2009 $test = StringSplit("124,12354,A234,23A,fe345,34,1,343", ',') For $i = 1 To UBound($test) - 1 If StringRegExp($test[$i], '\A\d{3}$', 0) = 1 Then ConsoleWrite("! MATCH : " & $test[$i] & @CRLF) Else ConsoleWrite("+> NO MATCH : " & $test[$i] & @CRLF) EndIf Next Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
SpinningCone Posted January 13, 2009 Author Share Posted January 13, 2009 Edit: I misread the at least part. Try this:Local $a_sample[4] = ["junk1234junk","123","1234","j12"] For $i = 0 To UBound($a_sample) - 1 If StringRegExp($a_sample[$i], "^\d\d\d+$") Then MsgBox(64, "Info", "Array Element " & $i & " is true." & @CRLF & $a_sample[$i]) EndIf Next Ahh yes that one seems to work. Thank you it's much less klunky than the nested IF statement. looks like Xenobiologist also missed the "least" part of it, his code returns ! MATCH : 124 +> NO MATCH : 12354 +> NO MATCH : A234 +> NO MATCH : 23A +> NO MATCH : fe345 +> NO MATCH : 34 +> NO MATCH : 1 ! MATCH : 343 where 12354 should be a match. nice use of console write as opposed to message boxes tho 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