lua-users home
lua-l archive

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


On 03/05/2011 01:00 PM, Dmitriy Kryuk wrote:
Lua patterns support a capture of type %bxy that captures a sequence of
characters with 'x' and 'y' balanced. This can be inappropriate for the
cases where those characters can represent not the "bracket structure" only,
but appear "escaped" as ordinary characters.
I propose a patch that adds a %Bxyz capture type to Lua. It stands for
"sequence of characters with balanced 'x' and 'y' characters where any
character right after a 'z' is treated just as an ordinary character, not
the one to balance".
I have used it to parse Apache log files like this:
str = '"GET /A\\"B HTTP/1.1"'
str:match('%B""\\') -- captures the whole string

I find this very useful for a variety of tasks, and it greatly eases the implementation of this recent list post:
http://vlists.pepperfish.net/cgi-bin/mailman/private/lua-l-lists.lua.org/2011-February/008124.html

-- David