Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:StringTools
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local p = {} --[=[ Similar to gmatch, but it returns the count of the match in addition to the list of captures, something like ipairs(). If the pattern doesn't contain any captures, the whole match is returned. Invoke thus: for i, whole_match in require("Module:string").imatch(text, pattern) do [ do something with i and whole_match ] end or for i, capture1[, capture2[, capture3[, ...]]] in require("Module:string").imatch(text, pattern) do [ do something with i and capture1 ] end ]=] function p.imatch(text, pattern, start, plain) local i = 0 local pos = start or 0 if not mw.ustring.find(pattern, "%b()") then pattern = "(" .. pattern .. ")" end return function() i = i + 1 local return_values = { mw.ustring.find(text, pattern, pos, plain) } local j = return_values[2] if #return_values > 0 then pos = j + 1 -- Skip the first two returned values, which are the indices of the -- whole match. return i, unpack(return_values, 3) else return nil, nil end end end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:StringTools/doc
(
edit
)