kelvin76 Posted June 30, 2016 Posted June 30, 2016 Hi Experts, My current situation is this, is there anyway for stringregexp to match more then 1 pattern, assume the data which i load from my Table data will loop from j=0 to $UBOUND_COLUMNS -1, which mean when they loop thru all the columns, there will be various data like 'apple', 'orange', 'banana' in each column, like j=0 data is apple, j=1 data is orange, j=2 data is banana. As such, i was wondering if the pattern matching can be something like this $asResult = StringRegExp($aTableData[5][$j], '(APPLE)' | ' (ORANGE)' | '(BANANA)', 1) Hope that i am clear as my native language is not english. Thanks alot guys/gals. Cheers Regards
jchd Posted June 30, 2016 Posted June 30, 2016 Looking at the help for StringRegExp would have shown that alternation is the way to go. You almos got the syntax correct: $asResult = StringRegExp($aTableData[5][$j], '(APPLE|ORANGE|BANANA)', 1) This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
Malkey Posted June 30, 2016 Posted June 30, 2016 Just clarifying looping thru all the columns in a row in the first example, And, looping thru all the rows in a column in the second example. expandcollapse popup#include <Array.au3> Local $sRet ; First Example $sRet = " -- $aTableData[2][5] -- Loop thru all the columns in a row." & @LF Local $aTableData[2][5] = [["APPLE", "PEAR", "ORANGE", "PLUM", "BANANA"],[3, 1, 2, 4, 5]] _ArrayDisplay($aTableData, "$aTableData[2][5]") For $j = 0 To UBound($aTableData, 2) - 1 If StringRegExp($aTableData[0][$j], '(APPLE|ORANGE|BANANA)') Then $sRet &= "$aTableData[0][" & $j & "] = " & $aTableData[0][$j] & @TAB & _ "$aTableData[1][" & $j & "] = " & $aTableData[1][$j] & @LF EndIf Next ; ----- OR ----------- ; Second Example $sRet &= @LF & " -- $aTableData[5][2] -- Loop thru all the rows in a column." & @LF Local $aTableData[5][2] = [["APPLE", 3],["PEAR", 1],["ORANGE", 2],["PLUM", 4],["BANANA", 5]] _ArrayDisplay($aTableData, "$aTableData[5][2]") For $j = 0 To UBound($aTableData) - 1 If StringRegExp($aTableData[$j][0], '(APPLE|ORANGE|BANANA)') Then $sRet &= "$aTableData[" & $j & "][0] = " & $aTableData[$j][0] & @TAB & _ "$aTableData[" & $j & "][1] = " & $aTableData[$j][1] & @LF EndIf Next ConsoleWrite($sRet) #cs Returns :- ----- $aTableData[2][5] ----- $aTableData[0][0] = APPLE $aTableData[1][0] = 3 $aTableData[0][2] = ORANGE $aTableData[1][2] = 2 $aTableData[0][4] = BANANA $aTableData[1][4] = 5 ----- $aTableData[5][2] ----- $aTableData[0][0] = APPLE $aTableData[0][1] = 3 $aTableData[2][0] = ORANGE $aTableData[2][1] = 2 $aTableData[4][0] = BANANA $aTableData[4][1] = 5 #ce
kelvin76 Posted July 7, 2016 Author Posted July 7, 2016 Hi Guys, Thanks for the reply. Was busy the pass week. I finally got it right with the below expression. My program only loop thru the second column and check that the second column contains either of the 3 fruits and make some decision base on it. $asResult = StringRegExp($aTableData[5][$j], '(?|(Apple)|(Orange)|(Banana), 3)
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