gcue Posted May 28, 2015 Posted May 28, 2015 hello worldi am currently using this$aDate = StringRegExp($date, "(?i)(\V+)(\d{8})\V(\d{4})", 3)to successfullly match these$string = "IMG00136-20100524-0109"$string = "IMG00136_20100524_0109"$string = "IMG_20000526_100019_402"$string = "IMG-20120615-00028"$string = "IMG_20120615_00028"$string = "Texas-20111117-00060"$string = "Texas_20111117_00060"$string = "Southwest San Marcos Valley-20111110-00046"$string = "Southwest San Marcos Valley_20111110_00046"$string = "Long Island-Laketown-20110526-00023"$string = "Long Island-Laketown_20110526_00023"however these do not match unless i add an \A at the beginning (but if i do that then the ones above do not match)$string = "20141119_193702"$string = "20141119-193702" any way to match both?thanks in advance !
mikell Posted May 28, 2015 Posted May 28, 2015 You might want something like this#Include <Array.au3> $string = "" $string &= "IMG00136-20100524-0109" & @crlf $string &= "IMG00136_20100524_0109" & @crlf $string &= "IMG_20000526_100019_402" & @crlf $string &= "IMG-20120615-00028" & @crlf $string &= "IMG_20120615_00028" & @crlf $string &= "Texas-20111117-00060" & @crlf $string &= "Texas_20111117_00060" & @crlf $string &= "Southwest San Marcos Valley-20111110-00046" & @crlf $string &= "Southwest San Marcos Valley_20111110_00046" & @crlf $string &= "Long Island-Laketown-20110526-00023" & @crlf $string &= "Long Island-Laketown_20110526_00023" & @crlf $string &= "20141119_193702" & @crlf $string &= "20141119-193702" $aDate = StringRegExp($string, "(?i)(\V*)(\d{8})\V(\d{4})", 4) ; $STR_REGEXPARRAYGLOBALFULLMATCH Local $res[UBound($aDate)][3] For $i = 0 to UBound($aDate)-1 $res[$i][0] = ($aDate[$i])[1] $res[$i][1] = ($aDate[$i])[2] $res[$i][2] = ($aDate[$i])[3] Next _ArrayDisplay($res) jguinch and iamtheky 2
jguinch Posted May 28, 2015 Posted May 28, 2015 Very nice mikell. I like the use of $STR_REGEXPARRAYGLOBALFULLMATCH. I didn't know it was possible to call directly a subarray item with ($aDate[$i])[1]. Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
iamtheky Posted May 28, 2015 Posted May 28, 2015 (edited) best example for magic number 4 I have seen, that needs its own thread. Even moreso with the direct access of an array in an array.Seriously Mikell, i think you have most certainly added back into routine consideration, a storage option I had disregarded for the most part as being cumbersome compared to alternatives. I would call this shorthand, but is there a proper name for that type of syntax, that would be a fitting title for a thread consisting of examples? Edited May 28, 2015 by boththose ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
mikell Posted May 29, 2015 Posted May 29, 2015 About alternatives you probably mean this commonly used one$aDate = StringRegExp($string, "(?i)(\V*)(\d{8})\V(\d{4})", 3) ; $STR_REGEXPARRAYGLOBALMATCH Local $res[UBound($aDate)/3][3] For $i = 0 to UBound($res)-1 $res[$i][0] = $aDate[$i*3] $res[$i][1] = $aDate[$i*3+1] $res[$i][2] = $aDate[$i*3+2] Next _ArrayDisplay($res)But I personally prefer the flag 4 regexReferring to the last example in the helpfile this flag 4 way could be written like this$aDate = StringRegExp($string, "(?i)(\V*)(\d{8})\V(\d{4})", 4) ; $STR_REGEXPARRAYGLOBALFULLMATCH Local $res[UBound($aDate)][3] For $i = 0 to UBound($aDate)-1 $aMatch = $aDate[$i] $res[$i][0] = $aMatch[1] $res[$i][1] = $aMatch[2] $res[$i][2] = $aMatch[3] Next _ArrayDisplay($res)Concerning the ($aDate[$i])[1] syntax I don't know where it's mentioned in the helpfileI saw it once in a topic and found it very useful and handy so I kept this tip stored into a couple of little grey cells for further use
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