]=]  
local et_al_patterns = {
"[;,]? *[\"']*%f[%a][Ee][Tt]%.? *[Aa][Ll][%.;,\"']*$", -- variations on the 'et al' theme
"[;,]? *[\"']*%f[%a][Ee][Tt]%.? *[Aa][Ll][Ii][AaIi][Ee]?[%.;,\"']*$", -- variations on the 'et alia', 'et alii' and 'et aliae' themes (false positive 'et aliie' unlikely to match)
"[;,]? *%f[%a]and [Oo]thers", -- an alternative to et al.
}  
-----------------------< N A M E _ H A S _ E T A L >--------------------------  
This adapted from Module:Citation/CS1  
Evaluates the content of a name for variations on the theme of et al. If found,
returns true; nil else  
local function name_has_etal (name)
local etal;  
if name then -- name can be nil in which case just return
name = name:gsub ('%b<>', ''); -- remove any html markup (typically <i>...</i>)
for _, pattern in ipairs (et_al_patterns) do -- loop through all of the patterns
if name:match (pattern) then -- if this 'et al' pattern is found in name
return true; -- has etal, so return true
end
end
end
end  
--authorn= parameters from the list of names provided in the raw iucn citation. names
must have the form: Surname, I. (more than one 'I.' pair allowed but no spaces between I. pairs)  
assumes that parenthetical text at the end of the author-name-list is a collaboration
Name, I.I., & Name, I.I. (Colaboration name)  
assumes that <i>et al.</i> is the last name in a list of names  
--local function author_names_get (raw_iucn_cite)
local function author_names_get (raw_iucn_cite, params_t) -- EXPERIMENT
local list = {}; -- table that holds name list parts
local author_names = raw_iucn_cite:match ('^([^%d]-)%s+%d%d%d%d'); -- extract author name-list from raw iucn citation
local collaboration = author_names:match ('%s*(%b)$'); -- get collaboration name if it exists  
if collaboration then -- when there is a colaboration
collaboration = collaboration:gsub ('[%(%)]', ''); -- remove bounding parentheses
author_names = author_names:gsub ('%s*(%b)$', ''); -- and remove collaboration from author-name-list
end  
local names = author_names:gsub ('%.?,?%s+&%s+', '.|'); -- replace 'separators' (<optional dot><optional comma><space><ampersand><space>) with <dot><pipe>
names = names:gsub ('%.,%s*', '.|'); -- replace 'separators' (<dot><comma><optional space>) with <dot><pipe>
names = names:gsub ('(%.%u),', '%1.|'); -- special case for when last initial is missing its trailing dot
list = mw.text.split (names, '|'); -- split the string on the pipes into entries in list{}  
if 0 == #list then
params_t['author'] = author_names; -- EXPERIMENT
return table.concat ({'|author=', author_names}), params_t; -- EXPERIMENT -- no 'names' of the proper form; return the original as a single |author= parameter
-- return table.concat ({'|author=', author_names}) -- no 'names' of the proper form; return the original as a single |author= parameter
else
for i, name in ipairs (list) do -- spin through the list and
if name_has_etal (name) then -- if this name has some form of 'et al'
params_t['display-authors'] = 'etal'; -- EXPERIMENT
list[i] = '|display-authors=etal'; -- add |dispaly-authors=etal parameter and
break; -- assume that the etal was the last 'name' so stop processing names
else
params_t['author' .. i] = name; -- EXPERIMENT
list[i] = table.concat ({'|author', (i == 1) and '' or i, '=', name}); -- add |authorn= parameter names; create |author= instead of |author1=
end
end
if collaboration then
params_t['collaboration'] = collaboration; -- EXPERIMENT
table.insert (list, table.concat ({'|collaboration', '=', collaboration})); -- add |collaboration= parameter
end
return table.concat (list, ' '); -- make a big string and return that
end
end  
----------------------------< T I T L E _ G E T >------------------------------------------------------------  
extract and format citation title; attempts to get the italic  
*binomen* (amended or errata title)
*binomen*
*binomen* ssp. *subspecies*
*binomen* subsp. *subspecies*
*binomen* var. *variety*
*binomen* subvar. *subvariety*  
all of the above may have trailing amended or errata text in parentheses  
TODO: are there others?  
local function title_get (raw_iucn_cite)
local title = raw_iucn_cite:match ('%d%d%d%d%.%s+(.-)%s*%. The IUCN Red List of Threatened Species');  
local patterns = { -- tables of string.match patterns [1] and string.gsub patterns [2]
{'(.-)%sssp%.%s+(.-)%s(%b)$', "*%1* ssp. *%2* %3"}, -- binomen ssp. subspecies (zoology) with errata or amended text
{'(.-)%sssp%.%s+(.+)', "*%1* ssp. *%2*"}, -- binomen ssp. subspecies (zoology)
{'(.-)%ssubsp%.%s+(.-)%s(%b)$', "*%1* subsp. *%2* %3"}, -- binomen subsp. subspecies (botany) with errata or amended text
{'(.-)%ssubsp%.%s+(.+)', "*%1* subsp. *%2*"}, -- binomen subsp. subspecies (botany)
{'(.-)%svar%.%s+(.-)%s+(%b)$', "*%1* var. *%2* %3"}, -- binomen var. variety (botany) with errata or amended text
{'(.-)%svar%.%s+(.+)', "*%1* var. *%2*"}, -- binomen var. variety (botany)
{'(.-)%ssubvar%.%s+(.-)%s(%b)$', "*%1* subvar. *%2* %3"}, -- binomen subvar. subvariety (botany) with errata or amended text
{'(.-)%ssubvar%.%s+(.+)', "*%1* subvar. *%2*"}, -- binomen subvar. subvariety (botany)
{'(.-)%s*(%b)$', "*%1* %2"}, -- binomen with errata or amended text
{'(.+)', "*%1*"}, -- binomen
}  
for i, v in ipairs (patterns) do -- spin through the patterns
if title:match (v[1]) then -- when a match
title = title:gsub (v[1], v[2]); -- add italics
break; -- and done
end
end  
-- return table.concat ({' |title=', title}); -- return the |title= parameter
return title; -- return the formatted title
end  
----------------------------< M A K E _ C I T E _ I U C N >--------------------------------------------------  
parses apart an iucn-format citation copied from their webpage and reformats that into a template for substing  
automatic substing by User:AnomieBOT/docs/TemplateSubster  
local function make_cite_iucn
local args_t = getArgs ;
local raw_iucn_cite = args_t[1];  
local template_t = {''); -- close the template  
if args_t[2] then -- if anything in args_t[2], write a nowiki'd version that editors can copy into ')
end  
return :preprocess (table.concat (template_t)); -- render template; substable
end  
----------------------------< E X P O R T E D F U N C T I O N S >------------------------------------------  
return {
cite = cite,
make_cite_iucn = make_cite_iucn,
}