function RegMatch inText, inExpr -- 20180604
local leftBraces = "[[", rightBraces = "]]", regex = merge("txt=`[[inText]]`;regex=`[[inExpr]]`;if [[leftBraces]] `$txt` =~ $regex [[rightBraces]];then echo `TRUE[[cr]]`$BASH_REMATCH;else echo `FALSE`;fi")
return unixTask("", "/bin/bash", "-c", regex)
end RegMatch
As an exemple, in this case:
inText = "CO 2345"
inExpr = "^(A|AA|B|BA|BC|BO|BR|C|CR|CM|CO|DA|DN|DM|DO|EO|EQ|EP|ER|ET|EX|HT|ST|ZT) +[0-9]+ ?[0-9]?[0-9]?[0-9]?[ABCDEFGHIJKL]?"
After merging:
regex = "txt="CO 2345";regex="^(A|AA|B|BA|BC|BO|BR|C|CR|CM|CO|DA|DN|DM|DO|EO|EQ|EP|ER|ET|EX|HT|ST|ZT) +[0-9]+ ?[0-9]?[0-9]?[0-9]?[ABCDEFGHIJKL]?";if [[ "$txt" =~ $regex ]];then echo "TRUE
"$BASH_REMATCH;else echo "FALSE";fi"
If I paste regex in Terminal in OS X High Sierra, I am getting this right result:
TRUE
CO 1234
If I paste regex in Terminal in OS X Tiger, the command get mangled in this way:
MiniBay:~ minibay$ txt="CO 1234";regex="^(A|AA|B|BA|BC|BO|BR|C|CR|CM|CO|DA|DN|DM|DO|EO|EQ|EP|ER|ET|EX|HT|ST|ZT) +[0-9]+ ?[0-9]?[0-9]?[0-9]?[ABCDEFGHIJKL]?";if [[ "$txt" =~ $regex ]];then echo "TRUE
-bash: conditional binary operator expected
-bash: syntax error near `=~'
MiniBay:~ minibay$ "$BASH_REMATCH;else echo "FALSE";fi
I wonder where is the error in the RegEx expression while being with OS X Tiger?
I suppose it is not possible to have an expression that would be valid for OS X Tiger and up!
But by using the SC function systemVersion(long), I can intercept the system version and put the right RegEx expression accordingly!
Maybe someone would have a clue?
Regards
André Tremblay
PhotoGraphex