EyeonTips:Script/Reference/Libraries/string/find
From VFXPedia
string.find uses regular expressions which means that some characters (like dots or asterisks) have special meanings and mess with your expected result. For example, if you want to test for a certain file extension by using
string.find(mypath, ".comp")
you will be surprised get a positive result on a file called "too_complicated.jpg". This is because in regular expressions, the dot is a wildcard for any character. To actually search for the desired file extensions, use this:
-- % turns the dot into an actual dot instead of a wildcard -- $ only allows the hit to occur at the end of the string string.find(mypath, "%.comp$")
There's a fourth parameter to this function. According to the LUA referece manual:
A value of true as a fourth, optional argument plain turns off the pattern matching facilities, so the function does a plain "find substring" operation, with no characters in pattern being considered "magic". Note that if plain is given, then init must be given as well.
Thus, a more correct version without regular expressions would be this:
string.find(mypath, ".comp", 1, true)
However, regular expressions are still superior because the command above doesn't require ".comp" to be at the end of the file name.