lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On 28 May 2012 20:55, Mike McGonagle <> wrote:
> Guess I got C on the brain as I was trying to escape it, but with a "\"
> instead. Time to read those pattern tutorials more closely.

Lua also uses '\' as an escape character in string literals, just like
C. However unlike standard regex dialects, Lua's patterns use '%' as
an escape.

You soon grow to appreciate this... just like in C when we want to
write '\' in a string in Lua we have to write "\\". This would make it
very inconvenient if patterns used '\' extensively. It makes more
sense to use a different character (Lua chose '%') instead, so we can
use "%a" to match an alphanumeric character rather than having to
write "\\a" ("\a" would translate to ASCII char 7, just as in C).