Module:TableTools: Difference between revisions

escape prefix and suffix strings in affixNums so that magic characters are interpreted literally
Enwikipedia>Mr. Stradivarius
(add p.numData function)
Enwikipedia>Mr. Stradivarius
(escape prefix and suffix strings in affixNums so that magic characters are interpreted literally)
Line 133:
checkType('affixNums', 2, prefix, 'string', true)
checkType('affixNums', 3, suffix, 'string', true)
 
local function cleanPattern(s)
-- Cleans a pattern so that the magic characters ()%.[]*+-?^$ are interpreted literally.
s = s:gsub('([()%%.%[%]*+-?^$])', '%%%1')
return s
end
 
prefix = prefix or ''
suffix = suffix or ''
prefix = cleanPattern(prefix)
suffix = cleanPattern(suffix)
local pattern = '^' .. prefix .. '([1-9]%d*)' .. suffix .. '$'
 
local nums = {}
for k, v in pairs(t) do