Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- This function behaves just like gmatch, but it also returns the position
- in the line of the match.
- @return iterator function which returns the start, stop, and textual match of every
- occurence of the given pattern.
- Example:
- for start, stop, match in gfind (str, pat) do
- ...
- end
- ]]
- local function gfind (_string, pattern)
- if not _string or not pattern then
- error ("Arguments to gfind are invalid: faulty string or pattern.")
- end
- local start, stop;
- return function()
- if stop then
- stop = stop + 1
- end
- start, stop = _string:find (pattern, stop)
- return start, stop, (start ~= nil) and _string:sub (start, stop) or nil
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement