[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Understanding Strings
- From: Matthew Wild <mwild1@...>
- Date: Mon, 28 May 2012 21:40:01 +0100
On 28 May 2012 20:55, Mike McGonagle <mjmogo@gmail.com> 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).
Regards,
Matthew