Home
Random
Log in
Settings
About Chabadpedia
Chabadpedia
Search
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
Edit summary
(Briefly describe your changes)
Please note that all contributions to Chabadpedia are considered to be released under the GNU Free Documentation License 1.3 or later (see
Chabadpedia:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, 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.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:StringTools/doc
(
edit
)