lua-users home
lua-l archive

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


On Tue, Jan 5, 2016 at 4:44 PM, Pierre-Yves Gérardy <pygy79@gmail.com> wrote:
> On Tue, Jan 5, 2016 at 5:41 AM, Jonathan Goble <jcgoble3@gmail.com> wrote:
>> My suggestion is to add the token %B, which would perform the same
>> thing as %b, except it would recognize an escape character specified
>> in the arguments to the token, and upon encountering the escape
>> character, the following character would be ignored. I doubt it would
>> handle all use cases, but it almost certainly would handle a large
>> percentage.
>
> Does it handle escaping the escape character?
>
> (' - "foo\\"bar" - '):match([["\"]]
> (' - "foo\\\"bar" - '):match([["\"]]
>
> —Pierre-Yves

Yes; the matcher simply iterates over the string one character at a
time, except that when it encounters an escape character, the next
character, whatever it is, is ignored.

So your examples, tweaked to use raw strings for clarity:

> ([[ - "foo\"bar" - ]]):match([[%B"\"]])
"foo\"bar"  -- \ escapes the "
> ([[ - "foo\\"bar" - ]]):match([[%B"\"]])
"foo\\"  -- first \ escapes the second \, and " is then matched