[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Pattern matching proposal: %B to match balanced string with specified escape
- From: Jonathan Goble <jcgoble3@...>
- Date: Tue, 5 Jan 2016 16:55:49 -0500
On Tue, Jan 5, 2016 at 4:44 PM, Pierre-Yves Gérardy <email@example.com> wrote:
> On Tue, Jan 5, 2016 at 5:41 AM, Jonathan Goble <firstname.lastname@example.org> 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
> Does it handle escaping the escape character?
> (' - "foo\\"bar" - '):match([["\"]]
> (' - "foo\\\"bar" - '):match([["\"]]
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