<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://the-democratika.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3AString2</id>
	<title>Module:String2 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://the-democratika.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3AString2"/>
	<link rel="alternate" type="text/html" href="https://the-democratika.com/wiki/index.php?title=Module:String2&amp;action=history"/>
	<updated>2026-04-04T14:40:00Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>https://the-democratika.com/wiki/index.php?title=Module:String2&amp;diff=6276&amp;oldid=prev</id>
		<title>&gt;Gonnym: fix</title>
		<link rel="alternate" type="text/html" href="https://the-democratika.com/wiki/index.php?title=Module:String2&amp;diff=6276&amp;oldid=prev"/>
		<updated>2025-02-19T12:24:59Z</updated>

		<summary type="html">&lt;p&gt;fix&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;require (&amp;#039;strict&amp;#039;);&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
p.trim = function(frame)&lt;br /&gt;
	return mw.text.trim(frame.args[1] or &amp;quot;&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
p.sentence = function (frame)&lt;br /&gt;
	-- {{lc:}} is strip-marker safe, string.lower is not.&lt;br /&gt;
	frame.args[1] = frame:callParserFunction(&amp;#039;lc&amp;#039;, frame.args[1])&lt;br /&gt;
	return p.ucfirst(frame)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
p.ucfirst = function (frame)&lt;br /&gt;
	local s = frame.args[1];&lt;br /&gt;
	if not s or &amp;#039;&amp;#039; == s or s:match (&amp;#039;^%s+$&amp;#039;) then								-- when &amp;lt;s&amp;gt; is nil, empty, or only whitespace&lt;br /&gt;
		return s;																-- abandon because nothing to do&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	s =  mw.text.trim( frame.args[1] or &amp;quot;&amp;quot; )&lt;br /&gt;
	local s1 = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	local prefix_patterns_t = {													-- sequence of prefix patterns&lt;br /&gt;
		&amp;#039;^\127[^\127]*UNIQ%-%-%a+%-%x+%-QINU[^\127]*\127&amp;#039;,						-- stripmarker&lt;br /&gt;
		&amp;#039;^([%*;:#]+)&amp;#039;,															-- various list markup&lt;br /&gt;
		&amp;#039;^(\&amp;#039;\&amp;#039;\&amp;#039;*)&amp;#039;,															-- bold / italic markup&lt;br /&gt;
		&amp;#039;^(%b&amp;lt;&amp;gt;)&amp;#039;,																-- html-like tags because some templates render these&lt;br /&gt;
		&amp;#039;^(&amp;amp;%a+;)&amp;#039;,																-- html character entities because some templates render these&lt;br /&gt;
		&amp;#039;^(&amp;amp;#%d+;)&amp;#039;,															-- html numeric (decimal) entities because some templates render these&lt;br /&gt;
		&amp;#039;^(&amp;amp;#x%x+;)&amp;#039;,															-- html numeric (hexadecimal) entities because some templates render these&lt;br /&gt;
		&amp;#039;^(%s+)&amp;#039;,																-- any whitespace characters&lt;br /&gt;
		&amp;#039;^([%(%)%-%+%?%.%%!~!@%$%^&amp;amp;_={}/`,‘’„“”ʻ|\&amp;quot;\&amp;#039;\\]+)&amp;#039;,					-- miscellaneous punctuation&lt;br /&gt;
		}&lt;br /&gt;
	&lt;br /&gt;
	local prefixes_t = {};														-- list, bold/italic, and html-like markup, &amp;amp; whitespace saved here&lt;br /&gt;
&lt;br /&gt;
	local function prefix_strip (s)												-- local function to strip prefixes from &amp;lt;s&amp;gt;&lt;br /&gt;
		for _, pattern in ipairs (prefix_patterns_t) do							-- spin through &amp;lt;prefix_patterns_t&amp;gt; &lt;br /&gt;
			if s:match (pattern) then											-- when there is a match&lt;br /&gt;
				local prefix = s:match (pattern);								-- get a copy of the matched prefix&lt;br /&gt;
				table.insert (prefixes_t, prefix);								-- save it&lt;br /&gt;
				s = s:sub (prefix:len() + 1);									-- remove the prefix from &amp;lt;s&amp;gt;&lt;br /&gt;
				return s, true;													-- return &amp;lt;s&amp;gt; without prefix and flag; force restart at top of sequence because misc punct removal can break stripmarker&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		return s;																-- no prefix found; return &amp;lt;s&amp;gt; with nil flag&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local prefix_removed;														-- flag; boolean true as long as prefix_strip() finds and removes a prefix&lt;br /&gt;
	&lt;br /&gt;
	repeat																		-- one by one remove list, bold/italic, html-like markup, whitespace, etc from start of &amp;lt;s&amp;gt;&lt;br /&gt;
		s, prefix_removed = prefix_strip (s);&lt;br /&gt;
	until (not prefix_removed);													-- until &amp;lt;prefix_removed&amp;gt; is nil&lt;br /&gt;
&lt;br /&gt;
	s1 = table.concat (prefixes_t);												-- recreate the prefix string for later reattachment&lt;br /&gt;
&lt;br /&gt;
	local first_text = mw.ustring.match (s, &amp;#039;^%[%[[^%]]+%]%]&amp;#039;);					-- extract wikilink at start of string if present; TODO: this can be string.match()?&lt;br /&gt;
&lt;br /&gt;
	local upcased;&lt;br /&gt;
	if first_text then&lt;br /&gt;
		if first_text:match (&amp;#039;^%[%[[^|]+|[^%]]+%]%]&amp;#039;) then						-- if &amp;lt;first_text&amp;gt; is a piped link&lt;br /&gt;
			upcased = mw.ustring.match (s, &amp;#039;^%[%[[^|]+|%W*(%w)&amp;#039;);				-- get first letter character&lt;br /&gt;
			upcased = mw.ustring.upper (upcased);								-- upcase first letter character&lt;br /&gt;
			s = mw.ustring.gsub (s, &amp;#039;^(%[%[[^|]+|%W*)%w&amp;#039;, &amp;#039;%1&amp;#039; .. upcased);		-- replace&lt;br /&gt;
		else																	-- here when &amp;lt;first_text&amp;gt; is a wikilink but not a piped link&lt;br /&gt;
			upcased = mw.ustring.match (s, &amp;#039;^%[%[%W*%w&amp;#039;);						-- get &amp;#039;[[&amp;#039; and first letter&lt;br /&gt;
			upcased = mw.ustring.upper (upcased);								-- upcase first letter character&lt;br /&gt;
			s = mw.ustring.gsub (s, &amp;#039;^%[%[%W*%w&amp;#039;, upcased);						-- replace; no capture needed here&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
	elseif s:match (&amp;#039;^%[%S+%s+[^%]]+%]&amp;#039;) then									-- if &amp;lt;s&amp;gt; is a ext link of some sort; must have label text&lt;br /&gt;
		upcased = mw.ustring.match (s, &amp;#039;^%[%S+%s+%W*(%w)&amp;#039;);						-- get first letter character&lt;br /&gt;
		upcased = mw.ustring.upper (upcased);									-- upcase first letter character&lt;br /&gt;
		s = mw.ustring.gsub (s, &amp;#039;^(%[%S+%s+%W*)%w&amp;#039;, &amp;#039;%1&amp;#039; .. upcased);			-- replace&lt;br /&gt;
	&lt;br /&gt;
	elseif s:match (&amp;#039;^%[%S+%s*%]&amp;#039;) then											-- if &amp;lt;s&amp;gt; is a ext link without label text; nothing to do&lt;br /&gt;
		return s1 .. s;															-- reattach prefix string (if present) and done&lt;br /&gt;
&lt;br /&gt;
	else																		-- &amp;lt;s&amp;gt; is not a wikilink or ext link; assume plain text&lt;br /&gt;
		upcased = mw.ustring.match (s, &amp;#039;^%W*%w&amp;#039;);								-- get the first letter character&lt;br /&gt;
		upcased = mw.ustring.upper (upcased);									-- upcase first letter character&lt;br /&gt;
		s = mw.ustring.gsub (s, &amp;#039;^%W*%w&amp;#039;, upcased);								-- replace; no capture needed here&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return s1 .. s;																-- reattach prefix string (if present) and done&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
p.title = function (frame)&lt;br /&gt;
	-- http://grammar.yourdictionary.com/capitalization/rules-for-capitalization-in-titles.html&lt;br /&gt;
	-- recommended by The U.S. Government Printing Office Style Manual:&lt;br /&gt;
	-- &amp;quot;Capitalize all words in titles of publications and documents,&lt;br /&gt;
	-- except a, an, the, at, by, for, in, of, on, to, up, and, as, but, or, and nor.&amp;quot;&lt;br /&gt;
	local alwayslower = {[&amp;#039;a&amp;#039;] = 1, [&amp;#039;an&amp;#039;] = 1, [&amp;#039;the&amp;#039;] = 1,&lt;br /&gt;
		[&amp;#039;and&amp;#039;] = 1, [&amp;#039;but&amp;#039;] = 1, [&amp;#039;or&amp;#039;] = 1, [&amp;#039;for&amp;#039;] = 1,&lt;br /&gt;
		[&amp;#039;nor&amp;#039;] = 1, [&amp;#039;on&amp;#039;] = 1, [&amp;#039;in&amp;#039;] = 1, [&amp;#039;at&amp;#039;] = 1, [&amp;#039;to&amp;#039;] = 1,&lt;br /&gt;
		[&amp;#039;from&amp;#039;] = 1, [&amp;#039;by&amp;#039;] = 1, [&amp;#039;of&amp;#039;] = 1, [&amp;#039;up&amp;#039;] = 1 }&lt;br /&gt;
	local res = &amp;#039;&amp;#039;&lt;br /&gt;
	local s =  mw.text.trim( frame.args[1] or &amp;quot;&amp;quot; )&lt;br /&gt;
	local words = mw.text.split( s, &amp;quot; &amp;quot;)&lt;br /&gt;
	for i, s in ipairs(words) do&lt;br /&gt;
		-- {{lc:}} is strip-marker safe, string.lower is not.&lt;br /&gt;
		s = frame:callParserFunction(&amp;#039;lc&amp;#039;, s)&lt;br /&gt;
		if i == 1 or alwayslower[s] ~= 1 then&lt;br /&gt;
			s = mw.getContentLanguage():ucfirst(s)&lt;br /&gt;
		end&lt;br /&gt;
		words[i] = s&lt;br /&gt;
	end&lt;br /&gt;
	return table.concat(words, &amp;quot; &amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- findlast finds the last item in a list&lt;br /&gt;
-- the first unnamed parameter is the list&lt;br /&gt;
-- the second, optional unnamed parameter is the list separator (default = comma space)&lt;br /&gt;
-- returns the whole list if separator not found&lt;br /&gt;
p.findlast = function(frame)&lt;br /&gt;
	local s =  mw.text.trim( frame.args[1] or &amp;quot;&amp;quot; )&lt;br /&gt;
	local sep = frame.args[2] or &amp;quot;&amp;quot;&lt;br /&gt;
	if sep == &amp;quot;&amp;quot; then sep = &amp;quot;, &amp;quot; end&lt;br /&gt;
	local pattern = &amp;quot;.*&amp;quot; .. sep .. &amp;quot;(.*)&amp;quot;&lt;br /&gt;
	local a, b, last = s:find(pattern)&lt;br /&gt;
	if a then&lt;br /&gt;
		return last&lt;br /&gt;
	else&lt;br /&gt;
		return s&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- stripZeros finds the first number and strips leading zeros (apart from units)&lt;br /&gt;
-- e.g &amp;quot;0940&amp;quot; -&amp;gt; &amp;quot;940&amp;quot;; &amp;quot;Year: 0023&amp;quot; -&amp;gt; &amp;quot;Year: 23&amp;quot;; &amp;quot;00.12&amp;quot; -&amp;gt; &amp;quot;0.12&amp;quot;&lt;br /&gt;
p.stripZeros = function(frame)&lt;br /&gt;
	local s = mw.text.trim(frame.args[1] or &amp;quot;&amp;quot;)&lt;br /&gt;
	local n = tonumber( string.match( s, &amp;quot;%d+&amp;quot; ) ) or &amp;quot;&amp;quot;&lt;br /&gt;
	s = string.gsub( s, &amp;quot;%d+&amp;quot;, n, 1 )&lt;br /&gt;
	return s&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- nowiki ensures that a string of text is treated by the MediaWiki software as just a string&lt;br /&gt;
-- it takes an unnamed parameter and trims whitespace, then removes any wikicode&lt;br /&gt;
p.nowiki = function(frame)&lt;br /&gt;
	local str = mw.text.trim(frame.args[1] or &amp;quot;&amp;quot;)&lt;br /&gt;
	return mw.text.nowiki(str)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- split splits text at boundaries specified by separator&lt;br /&gt;
-- and returns the chunk for the index idx (starting at 1)&lt;br /&gt;
-- #invoke:String2 |split |text |separator |index |true/false&lt;br /&gt;
-- #invoke:String2 |split |txt=text |sep=separator |idx=index |plain=true/false&lt;br /&gt;
-- if plain is false/no/0 then separator is treated as a Lua pattern - defaults to plain=true&lt;br /&gt;
p.split = function(frame)&lt;br /&gt;
	local args = frame.args&lt;br /&gt;
	if not(args[1] or args.txt) then args = frame:getParent().args end&lt;br /&gt;
	local txt = args[1] or args.txt or &amp;quot;&amp;quot;&lt;br /&gt;
	if txt == &amp;quot;&amp;quot; then return nil end&lt;br /&gt;
	local sep = (args[2] or args.sep or &amp;quot;&amp;quot;):gsub(&amp;#039;&amp;quot;&amp;#039;, &amp;#039;&amp;#039;)&lt;br /&gt;
	local idx = tonumber(args[3] or args.idx) or 1&lt;br /&gt;
	local plain = (args[4] or args.plain or &amp;quot;true&amp;quot;):sub(1,1)&lt;br /&gt;
	plain = (plain ~= &amp;quot;f&amp;quot; and plain ~= &amp;quot;n&amp;quot; and plain ~= &amp;quot;0&amp;quot;)&lt;br /&gt;
	local splittbl = mw.text.split( txt, sep, plain )&lt;br /&gt;
	if idx &amp;lt; 0 then idx = #splittbl + idx + 1 end&lt;br /&gt;
	return splittbl[idx]&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- val2percent scans through a string, passed as either the first unnamed parameter or |txt=&lt;br /&gt;
-- it converts each number it finds into a percentage and returns the resultant string.&lt;br /&gt;
p.val2percent = function(frame)&lt;br /&gt;
	local args = frame.args&lt;br /&gt;
	if not(args[1] or args.txt) then args = frame:getParent().args end&lt;br /&gt;
	local txt = mw.text.trim(args[1] or args.txt or &amp;quot;&amp;quot;)&lt;br /&gt;
	if txt == &amp;quot;&amp;quot; then return nil end&lt;br /&gt;
	local function v2p (x)&lt;br /&gt;
		x = (tonumber(x) or 0) * 100&lt;br /&gt;
		if x == math.floor(x) then x = math.floor(x) end&lt;br /&gt;
		return x .. &amp;quot;%&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
	txt = txt:gsub(&amp;quot;%d[%d%.]*&amp;quot;, v2p) -- store just the string&lt;br /&gt;
	return txt&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- one2a scans through a string, passed as either the first unnamed parameter or |txt=&lt;br /&gt;
-- it converts each occurrence of &amp;#039;one &amp;#039; into either &amp;#039;a &amp;#039; or &amp;#039;an &amp;#039; and returns the resultant string.&lt;br /&gt;
p.one2a = function(frame)&lt;br /&gt;
	local args = frame.args&lt;br /&gt;
	if not(args[1] or args.txt) then args = frame:getParent().args end&lt;br /&gt;
	local txt = mw.text.trim(args[1] or args.txt or &amp;quot;&amp;quot;)&lt;br /&gt;
	if txt == &amp;quot;&amp;quot; then return nil end&lt;br /&gt;
	txt = txt:gsub(&amp;quot; one &amp;quot;, &amp;quot; a &amp;quot;):gsub(&amp;quot;^one&amp;quot;, &amp;quot;a&amp;quot;):gsub(&amp;quot;One &amp;quot;, &amp;quot;A &amp;quot;):gsub(&amp;quot;a ([aeiou])&amp;quot;, &amp;quot;an %1&amp;quot;):gsub(&amp;quot;A ([aeiou])&amp;quot;, &amp;quot;An %1&amp;quot;)&lt;br /&gt;
	return txt&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- findpagetext returns the position of a piece of text in a page&lt;br /&gt;
-- First positional parameter or |text is the search text&lt;br /&gt;
-- Optional parameter |title is the page title, defaults to current page&lt;br /&gt;
-- Optional parameter |plain is either true for plain search (default) or false for Lua pattern search&lt;br /&gt;
-- Optional parameter |nomatch is the return value when no match is found; default is nil&lt;br /&gt;
p._findpagetext = function(args)&lt;br /&gt;
	-- process parameters&lt;br /&gt;
	local nomatch = args.nomatch or &amp;quot;&amp;quot;&lt;br /&gt;
	if nomatch == &amp;quot;&amp;quot; then nomatch = nil end&lt;br /&gt;
	--&lt;br /&gt;
	local text = mw.text.trim(args[1] or args.text or &amp;quot;&amp;quot;)&lt;br /&gt;
	if text == &amp;quot;&amp;quot; then return nil end&lt;br /&gt;
	--&lt;br /&gt;
	local title = args.title or &amp;quot;&amp;quot;&lt;br /&gt;
	local titleobj&lt;br /&gt;
	if title == &amp;quot;&amp;quot; then&lt;br /&gt;
		titleobj = mw.title.getCurrentTitle()&lt;br /&gt;
	else&lt;br /&gt;
		titleobj = mw.title.new(title)&lt;br /&gt;
	end&lt;br /&gt;
	--&lt;br /&gt;
	local plain = args.plain or &amp;quot;&amp;quot;&lt;br /&gt;
	if plain:sub(1, 1) == &amp;quot;f&amp;quot; then plain = false else plain = true end&lt;br /&gt;
	-- get the page content and look for &amp;#039;text&amp;#039; - return position or nomatch&lt;br /&gt;
	local content = titleobj and titleobj:getContent()&lt;br /&gt;
	return content and mw.ustring.find(content, text, 1, plain) or nomatch&lt;br /&gt;
end&lt;br /&gt;
p.findpagetext = function(frame)&lt;br /&gt;
	local args = frame.args&lt;br /&gt;
	local pargs = frame:getParent().args&lt;br /&gt;
	for k, v in pairs(pargs) do&lt;br /&gt;
		args[k] = v&lt;br /&gt;
	end&lt;br /&gt;
	if not (args[1] or args.text) then return nil end&lt;br /&gt;
	-- just the first value&lt;br /&gt;
	return (p._findpagetext(args))&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- returns the decoded url. Inverse of parser function {{urlencode:val|TYPE}}&lt;br /&gt;
-- Type is:&lt;br /&gt;
-- QUERY decodes + to space (default)&lt;br /&gt;
-- PATH does no extra decoding&lt;br /&gt;
-- WIKI decodes _ to space&lt;br /&gt;
p._urldecode = function(url, type)&lt;br /&gt;
	url = url or &amp;quot;&amp;quot;&lt;br /&gt;
	type = (type == &amp;quot;PATH&amp;quot; or type == &amp;quot;WIKI&amp;quot;) and type&lt;br /&gt;
	return mw.uri.decode( url, type )&lt;br /&gt;
end&lt;br /&gt;
-- {{#invoke:String2|urldecode|url=url|type=type}}&lt;br /&gt;
p.urldecode = function(frame)&lt;br /&gt;
	return mw.uri.decode( frame.args.url, frame.args.type )&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- what follows was merged from Module:StringFunc&lt;br /&gt;
&lt;br /&gt;
-- helper functions&lt;br /&gt;
p._GetParameters = require(&amp;#039;Module:GetParameters&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
-- Argument list helper function, as per Module:String&lt;br /&gt;
p._getParameters = p._GetParameters.getParameters&lt;br /&gt;
&lt;br /&gt;
-- Escape Pattern helper function so that all characters are treated as plain text, as per Module:String&lt;br /&gt;
function p._escapePattern( pattern_str )&lt;br /&gt;
	return mw.ustring.gsub( pattern_str, &amp;quot;([%(%)%.%%%+%-%*%?%[%^%$%]])&amp;quot;, &amp;quot;%%%1&amp;quot; )&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Helper Function to interpret boolean strings, as per Module:String&lt;br /&gt;
p._getBoolean = p._GetParameters.getBoolean&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
Strip&lt;br /&gt;
&lt;br /&gt;
This function Strips characters from string&lt;br /&gt;
&lt;br /&gt;
Usage:&lt;br /&gt;
{{#invoke:String2|strip|source_string|characters_to_strip|plain_flag}}&lt;br /&gt;
&lt;br /&gt;
Parameters&lt;br /&gt;
	source: The string to strip&lt;br /&gt;
	chars:  The pattern or list of characters to strip from string, replaced with &amp;#039;&amp;#039;&lt;br /&gt;
	plain:  A flag indicating that the chars should be understood as plain text. defaults to true.&lt;br /&gt;
&lt;br /&gt;
Leading and trailing whitespace is also automatically stripped from the string.&lt;br /&gt;
]]&lt;br /&gt;
function p.strip( frame )&lt;br /&gt;
	local new_args = p._getParameters( frame.args,  {&amp;#039;source&amp;#039;, &amp;#039;chars&amp;#039;, &amp;#039;plain&amp;#039;} )&lt;br /&gt;
	local source_str = new_args[&amp;#039;source&amp;#039;] or &amp;#039;&amp;#039;&lt;br /&gt;
	local chars = new_args[&amp;#039;chars&amp;#039;] or &amp;#039;&amp;#039; or &amp;#039;characters&amp;#039;&lt;br /&gt;
	source_str = mw.text.trim(source_str)&lt;br /&gt;
	if source_str == &amp;#039;&amp;#039; or chars == &amp;#039;&amp;#039; then&lt;br /&gt;
		return source_str&lt;br /&gt;
	end&lt;br /&gt;
	local l_plain = p._getBoolean( new_args[&amp;#039;plain&amp;#039;] or true )&lt;br /&gt;
	if l_plain then&lt;br /&gt;
		chars = p._escapePattern( chars )&lt;br /&gt;
	end&lt;br /&gt;
	local result&lt;br /&gt;
	result = mw.ustring.gsub(source_str, &amp;quot;[&amp;quot;..chars..&amp;quot;]&amp;quot;, &amp;#039;&amp;#039;)&lt;br /&gt;
	return result&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
Match any&lt;br /&gt;
Returns the index of the first given pattern to match the input. Patterns must be consecutively numbered.&lt;br /&gt;
Returns the empty string if nothing matches for use in {{#if:}}&lt;br /&gt;
&lt;br /&gt;
Usage:&lt;br /&gt;
	{{#invoke:String2|matchAll|source=123 abc|456|abc}} returns &amp;#039;2&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
	source: the string to search&lt;br /&gt;
	plain:  A flag indicating that the patterns should be understood as plain text. defaults to true.&lt;br /&gt;
	1, 2, 3, ...: the patterns to search for&lt;br /&gt;
]]&lt;br /&gt;
function p.matchAny(frame)&lt;br /&gt;
	local source_str = frame.args[&amp;#039;source&amp;#039;] or error(&amp;#039;The source parameter is mandatory.&amp;#039;)&lt;br /&gt;
	local l_plain = p._getBoolean( frame.args[&amp;#039;plain&amp;#039;] or true )&lt;br /&gt;
	for i = 1, math.huge do&lt;br /&gt;
		local pattern = frame.args[i]&lt;br /&gt;
		if not pattern then return &amp;#039;&amp;#039; end&lt;br /&gt;
		if mw.ustring.find(source_str, pattern, 1, l_plain) then&lt;br /&gt;
			return tostring(i)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; H Y P H E N _ T O _ D A S H &amp;gt;--------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
Converts a hyphen to a dash under certain conditions.  The hyphen must separate&lt;br /&gt;
like items; unlike items are returned unmodified.  These forms are modified:&lt;br /&gt;
	letter - letter (A - B)&lt;br /&gt;
	digit - digit (4-5)&lt;br /&gt;
	digit separator digit - digit separator digit (4.1-4.5 or 4-1-4-5)&lt;br /&gt;
	letterdigit - letterdigit (A1-A5) (an optional separator between letter and&lt;br /&gt;
		digit is supported – a.1-a.5 or a-1-a-5)&lt;br /&gt;
	digitletter - digitletter (5a - 5d) (an optional separator between letter and&lt;br /&gt;
		digit is supported – 5.a-5.d or 5-a-5-d)&lt;br /&gt;
&lt;br /&gt;
any other forms are returned unmodified.&lt;br /&gt;
&lt;br /&gt;
str may be a comma- or semicolon-separated list&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
function p.hyphen_to_dash( str, spacing )&lt;br /&gt;
	if (str == nil or str == &amp;#039;&amp;#039;) then&lt;br /&gt;
		return str&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local accept&lt;br /&gt;
&lt;br /&gt;
	str = mw.text.decode(str, true )											-- replace html entities with their characters; semicolon mucks up the text.split&lt;br /&gt;
&lt;br /&gt;
	local out = {}&lt;br /&gt;
	local list = mw.text.split (str, &amp;#039;%s*[,;]%s*&amp;#039;)								-- split str at comma or semicolon separators if there are any&lt;br /&gt;
&lt;br /&gt;
	for _, item in ipairs (list) do												-- for each item in the list&lt;br /&gt;
		item = mw.text.trim(item)												-- trim whitespace&lt;br /&gt;
		item, accept = item:gsub (&amp;#039;^%(%((.+)%)%)$&amp;#039;, &amp;#039;%1&amp;#039;)&lt;br /&gt;
		if accept == 0 and mw.ustring.match (item, &amp;#039;^%w*[%.%-]?%w+%s*[%-–—]%s*%w*[%.%-]?%w+$&amp;#039;) then	-- if a hyphenated range or has endash or emdash separators&lt;br /&gt;
			if item:match (&amp;#039;^%a+[%.%-]?%d+%s*%-%s*%a+[%.%-]?%d+$&amp;#039;) or			-- letterdigit hyphen letterdigit (optional separator between letter and digit)&lt;br /&gt;
				item:match (&amp;#039;^%d+[%.%-]?%a+%s*%-%s*%d+[%.%-]?%a+$&amp;#039;) or			-- digitletter hyphen digitletter (optional separator between digit and letter)&lt;br /&gt;
				item:match (&amp;#039;^%d+[%.%-]%d+%s*%-%s*%d+[%.%-]%d+$&amp;#039;) or			-- digit separator digit hyphen digit separator digit&lt;br /&gt;
				item:match (&amp;#039;^%d+%s*%-%s*%d+$&amp;#039;) or								-- digit hyphen digit&lt;br /&gt;
				item:match (&amp;#039;^%a+%s*%-%s*%a+$&amp;#039;) then							-- letter hyphen letter&lt;br /&gt;
					item = item:gsub (&amp;#039;(%w*[%.%-]?%w+)%s*%-%s*(%w*[%.%-]?%w+)&amp;#039;, &amp;#039;%1–%2&amp;#039;)	-- replace hyphen, remove extraneous space characters&lt;br /&gt;
			else&lt;br /&gt;
				item = mw.ustring.gsub (item, &amp;#039;%s*[–—]%s*&amp;#039;, &amp;#039;–&amp;#039;)				-- for endash or emdash separated ranges, replace em with en, remove extraneous whitespace&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		table.insert (out, item)												-- add the (possibly modified) item to the output table&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local temp_str = table.concat (out, &amp;#039;,&amp;#039; .. spacing)							-- concatenate the output table into a comma separated string&lt;br /&gt;
	temp_str, accept = temp_str:gsub (&amp;#039;^%(%((.+)%)%)$&amp;#039;, &amp;#039;%1&amp;#039;)					-- remove accept-this-as-written markup when it wraps all of concatenated out&lt;br /&gt;
	if accept ~= 0 then&lt;br /&gt;
		temp_str = str:gsub (&amp;#039;^%(%((.+)%)%)$&amp;#039;, &amp;#039;%1&amp;#039;)							-- when global markup removed, return original str; do it this way to suppress boolean second return value&lt;br /&gt;
	end&lt;br /&gt;
	return temp_str&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.hyphen2dash( frame )&lt;br /&gt;
	local str = frame.args[1] or &amp;#039;&amp;#039;&lt;br /&gt;
	local spacing = frame.args[2] or &amp;#039; &amp;#039; -- space is part of the standard separator for normal spacing (but in conjunction with templates r/rp/ran we may need a narrower spacing&lt;br /&gt;
&lt;br /&gt;
	return p.hyphen_to_dash(str, spacing)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Similar to [[Module:String#endswith]]&lt;br /&gt;
function p.startswith(frame)&lt;br /&gt;
	return (frame.args[1]:sub(1, frame.args[2]:len()) == frame.args[2]) and &amp;#039;yes&amp;#039; or &amp;#039;&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Implements [[Template:Isnumeric]]&lt;br /&gt;
function p.isnumeric(frame)&lt;br /&gt;
	local s = frame.args[1] or frame:getParent().args[1]&lt;br /&gt;
	local boolean = (frame.args.boolean or frame:getParent().args.boolean) == &amp;#039;true&amp;#039;&lt;br /&gt;
	if type(s) == &amp;#039;string&amp;#039; and mw.getContentLanguage():parseFormattedNumber( s ) then&lt;br /&gt;
		return boolean and 1 or s&lt;br /&gt;
	end&lt;br /&gt;
	return boolean and 0 or &amp;#039;&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Checks if a value in a group of numbers is not an interger.&lt;br /&gt;
-- Allows usage of an |empty= parameter to allow empty values to be skipped.&lt;br /&gt;
function p.isInteger(frame)&lt;br /&gt;
	local values = frame.args or frame:getParent().args&lt;br /&gt;
	local allow_empty = frame.args.empty or frame:getParent().args.empty&lt;br /&gt;
&lt;br /&gt;
	for _, value in ipairs(values) do&lt;br /&gt;
		-- Trim spaces&lt;br /&gt;
		value = value and value:gsub(&amp;quot;^%s*(.-)%s*$&amp;quot;, &amp;quot;%1&amp;quot;)&lt;br /&gt;
		if value == &amp;quot;&amp;quot; or value == nil then&lt;br /&gt;
			if not allow_empty then&lt;br /&gt;
				return false  -- Empty values are not allowed&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			value = tonumber(value)&lt;br /&gt;
			if not (type(value) == &amp;quot;number&amp;quot; and value == math.floor(value)) then&lt;br /&gt;
				return false&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return true&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Returns an error found in a string.&lt;br /&gt;
function p.getError(frame)&lt;br /&gt;
	local text = frame.args[1] or frame:getParent().args[1]&lt;br /&gt;
	local error_message = text:match(&amp;#039;(&amp;lt;strong class=&amp;quot;error&amp;quot;&amp;gt;.-&amp;lt;/strong&amp;gt;)&amp;#039;)&lt;br /&gt;
	return error_message or nil&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>&gt;Gonnym</name></author>
	</entry>
</feed>