[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Feature request: plain option for gsub
- From: Petite Abeille <petite.abeille@...>
- Date: Thu, 21 Aug 2014 20:55:31 +0200
On Aug 21, 2014, at 5:57 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> That "lengthy" is a challenge ...
Just for fun, a convoluted global find, gfind, just because… :P
local function gfind( aString, aPattern, isPlain )
assert( type( aString ) == 'string' )
assert( type( aPattern ) == 'string' )
if isPlain then aPattern = aPattern:gsub( '%p', '%%%1' ) end
aPattern = ( '()(%s)()' ):format( aPattern )
return coroutine.wrap( function() for aStart, _, anEnd in aString:gmatch( aPattern ) do coroutine.yield( aStart, anEnd ) end end )
end
for aStart, anEnd in gfind( 'aa aa aa', 'aa' ) do
print( aStart, anEnd )
end
1 3
4 6
7 9