Reputation: 1610
I'm currently just starting my first Lua program and I have a .csv file to read in. I want to check if the file I'm reading in is truely a .csv file.
I've tried regex similiar to these but they just don't work..
s = string.match(arg[1], "%A+\.csv$")
whats the correct way to do the regex in lua?
Upvotes: 0
Views: 3879
Reputation: 183381
In Lua patterns, you escape the meaning of a special character by using %
, not \
. Also, %A
means a non-letter; a letter is %a
(lowercase). So you seem to want one of these:
"^%a+%.csv$" <-- one or more letters, plus ".csv"
"^%a.*%.csv$" <-- a letter, plus zero or more characters, plus ".csv"
Upvotes: 3