funkey Posted May 17, 2010 Share Posted May 17, 2010 Use wildcards (* and ?) for filtering your arrays. #Include <Array.au3> Local $aTest Local $aArray[5] = ["abcde", "aabcd", "bcd", "aeiou", "asdf"] Local $aPattern[6] = ["*e", "aa*", "?cd", "*e*", "*d", "*d?"] _ArrayDisplay($aArray, "Original Array") For $i = 0 To UBound($aPattern) - 1 $aTest = _ArrayPatternMatch($aArray, $aPattern[$i]) _ArrayDisplay($aTest, "Filter: " & $aPattern[$i]) Next Func _ArrayPatternMatch($aArray, $sPattern) ;funkey May 17, 2010 If UBound($aArray, 0) <> 1 Then Return SetError(1, 0, "") ;no 1D-array Local $n = UBound($aArray) Local $aRes[$n], $j = 0 $sPattern = "^\Q" & $sPattern & "\E$" $sPattern = StringReplace($sPattern, "?", "\E.\Q") $sPattern = StringReplace($sPattern, "*", "\E.*\Q") For $i = 0 To $n - 1 If StringRegExp($aArray[$i], $sPattern, 0) Then $aRes[$j] = $aArray[$i] $j += 1 EndIf Next If $j = 0 Then Return SetError(2, 0, "") ;no match ReDim $aRes[$j] Return $aRes EndFunc Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
dmob Posted May 18, 2010 Share Posted May 18, 2010 Nice work, think I might find a use for this. 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