[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: extension to string.gmatch (structural regular expressions)
- From: "Duncan Cross" <duncan.cross@...>
- Date: Wed, 2 Jan 2008 14:38:59 +0000
This is not a bad idea. In the past I've used the handy
position-capturing () to do similar things with the existing gmatch:
local start = 1
local text = "Hello World"
for stop, match, newstart in string.gmatch(text, "()(l)()") do
local before = text:sub(start,stop-1)
start = newstart
local final = text:sub(start)
It's possible that could be wrapped up in a smart gmatch-wrapping
function that adds "()(" and ")()" around the given pattern and passes
through results from a coroutine-based iterator of some kind, but it
probably wouldn't be very nice.