Title: Module:String2 - freem URL Source: https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2 Markdown Content: [](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#) - [x] * [Home](https://freemwiki.com/wiki/Main_Page) * [Random](https://freemwiki.com/wiki/Special:Random) * [Log in](https://freemwiki.com/index.php?title=Special:UserLogin&returnto=Module%3AString2&returntoquery=mobileaction%3Dtoggle_view_mobile%26oldid%3D579752) * [Settings](https://freemwiki.com/index.php?title=Special:MobileOptions&returnto=Module%3AString2) * [About](https://freemwiki.com/wiki/About) * [Terms of Service](https://freemwiki.com/wiki/Terms_of_Service) [freem](https://freemwiki.com/wiki/Main_Page) Search # Module:String2 * [Language](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2 "Language") * [Watch](https://freemwiki.com/index.php?title=Special:UserLogin&returnto=Module%3AString2) * [Edit](https://freemwiki.com/index.php?title=Module:String2&action=edit) Revision as of 06:18, 21 October 2025 by [Lukegao](https://freemwiki.com/index.php?title=User:Lukegao&action=edit&redlink=1 "User:Lukegao (page does not exist)")([talk](https://freemwiki.com/index.php?title=User_talk:Lukegao&action=edit&redlink=1 "User talk:Lukegao (page does not exist)") | [contribs](https://freemwiki.com/wiki/Special:Contributions/Lukegao "Special:Contributions/Lukegao"))(1 revision imported) ([diff](https://freemwiki.com/index.php?title=Module:String2&diff=prev&oldid=579752 "Module:String2")) [← Older revision](https://freemwiki.com/index.php?title=Module:String2&direction=prev&oldid=579752 "Module:String2") | Latest revision (diff) | Newer revision → (diff) _Documentation for this module may be created at [Module:String2/doc](https://freemwiki.com/index.php?title=Module:String2/doc&action=edit&redlink=1 "Module:String2/doc (page does not exist)")_ [](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-1)require ('strict');[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-2)local p = {}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-3)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-4)p.trim = function(frame)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-5)return mw.text.trim(frame.args[1] or "")[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-6)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-7)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-8)p.sentence = function (frame)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-9)-- {{lc:}} is strip-marker safe, string.lower is not.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-10)frame.args[1] = frame:callParserFunction('lc', frame.args[1])[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-11)return p.ucfirst(frame)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-12)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-13)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-14)p.ucfirst = function (frame)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-15)local s = frame.args[1];[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-16)if not s or '' == s or s:match ('^%s+$') then-- when is nil, empty, or only whitespace[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-17)return s;-- abandon because nothing to do[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-18)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-19)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-20)s = mw.text.trim( frame.args[1] or "" )[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-21)local s1 = ""[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-22)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-23)local prefix_patterns_t = {-- sequence of prefix patterns[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-24)'^\127[^\127]*UNIQ%-%-%a+%-%x+%-QINU[^\127]*\127',-- stripmarker[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-25)'^([%*;:#]+)',-- various list markup[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-26)'^(\'\'\'*)',-- bold / italic markup[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-27)'^(%b<>)',-- html-like tags because some templates render these[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-28)'^(&%a+;)',-- html character entities because some templates render these[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-29)'^(&#%d+;)',-- html numeric (decimal) entities because some templates render these[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-30)'^(&#x%x+;)',-- html numeric (hexadecimal) entities because some templates render these[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-31)'^(%s+)',-- any whitespace characters[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-32)'^([%(%)%-%+%?%.%%!~!@%$%^&_={}/`,‘’„“”ʻ|\"\'\\]+)',-- miscellaneous punctuation[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-33)}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-34)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-35)local prefixes_t = {};-- list, bold/italic, and html-like markup, & whitespace saved here[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-36)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-37)local function prefix_strip (s)-- local function to strip prefixes from [](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-38)for _, pattern in ipairs (prefix_patterns_t) do-- spin through [](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-39)if s:match (pattern) then-- when there is a match[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-40)local prefix = s:match (pattern);-- get a copy of the matched prefix[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-41)table.insert (prefixes_t, prefix);-- save it[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-42)s = s:sub (prefix:len() + 1);-- remove the prefix from [](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-43)return s, true;-- return without prefix and flag; force restart at top of sequence because misc punct removal can break stripmarker[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-44)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-45)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-46)return s;-- no prefix found; return with nil flag[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-47)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-48)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-49)local prefix_removed;-- flag; boolean true as long as prefix_strip() finds and removes a prefix[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-50)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-51)repeat-- one by one remove list, bold/italic, html-like markup, whitespace, etc from start of [](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-52)s, prefix_removed = prefix_strip (s);[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-53)until (not prefix_removed);-- until is nil[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-54)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-55)s1 = table.concat (prefixes_t);-- recreate the prefix string for later reattachment[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-56)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-57)local first_text = mw.ustring.match (s, '^%[%[[^%]]+%]%]');-- extract wikilink at start of string if present; TODO: this can be string.match()?[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-58)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-59)local upcased;[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-60)if first_text then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-61)if first_text:match ('^%[%[[^|]+|[^%]]+%]%]') then-- if is a piped link[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-62)upcased = mw.ustring.match (s, '^%[%[[^|]+|%W*(%w)');-- get first letter character[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-63)upcased = mw.ustring.upper (upcased);-- upcase first letter character[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-64)s = mw.ustring.gsub (s, '^(%[%[[^|]+|%W*)%w', '%1' .. upcased);-- replace[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-65)else-- here when is a wikilink but not a piped link[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-66)upcased = mw.ustring.match (s, '^%[%[%W*%w');-- get '[[' and first letter[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-67)upcased = mw.ustring.upper (upcased);-- upcase first letter character[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-68)s = mw.ustring.gsub (s, '^%[%[%W*%w', upcased);-- replace; no capture needed here[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-69)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-70)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-71)elseif s:match ('^%[%S+%s+[^%]]+%]') then-- if is a ext link of some sort; must have label text[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-72)upcased = mw.ustring.match (s, '^%[%S+%s+%W*(%w)');-- get first letter character[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-73)upcased = mw.ustring.upper (upcased);-- upcase first letter character[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-74)s = mw.ustring.gsub (s, '^(%[%S+%s+%W*)%w', '%1' .. upcased);-- replace[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-75)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-76)elseif s:match ('^%[%S+%s*%]') then-- if is a ext link without label text; nothing to do[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-77)return s1 .. s;-- reattach prefix string (if present) and done[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-78)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-79)else-- is not a wikilink or ext link; assume plain text[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-80)upcased = mw.ustring.match (s, '^%W*%w');-- get the first letter character[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-81)upcased = mw.ustring.upper (upcased);-- upcase first letter character[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-82)s = mw.ustring.gsub (s, '^%W*%w', upcased);-- replace; no capture needed here[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-83)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-84)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-85)return s1 .. s;-- reattach prefix string (if present) and done[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-86)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-87)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-88)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-89)p.title = function (frame)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-90)-- http://grammar.yourdictionary.com/capitalization/rules-for-capitalization-in-titles.html[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-91)-- recommended by The U.S. Government Printing Office Style Manual:[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-92)-- "Capitalize all words in titles of publications and documents,[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-93)-- except a, an, the, at, by, for, in, of, on, to, up, and, as, but, or, and nor."[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-94)local alwayslower = {['a'] = 1, ['an'] = 1, ['the'] = 1,[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-95)['and'] = 1, ['but'] = 1, ['or'] = 1, ['for'] = 1,[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-96)['nor'] = 1, ['on'] = 1, ['in'] = 1, ['at'] = 1, ['to'] = 1,[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-97)['from'] = 1, ['by'] = 1, ['of'] = 1, ['up'] = 1 }[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-98)local res = ''[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-99)local s = mw.text.trim( frame.args[1] or "" )[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-100)local words = mw.text.split( s, " ")[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-101)for i, s in ipairs(words) do[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-102)-- {{lc:}} is strip-marker safe, string.lower is not.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-103)s = frame:callParserFunction('lc', s)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-104)if i == 1 or alwayslower[s] ~= 1 then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-105)s = mw.getContentLanguage():ucfirst(s)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-106)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-107)words[i] = s[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-108)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-109)return table.concat(words, " ")[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-110)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-111)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-112)-- findlast finds the last item in a list[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-113)-- the first unnamed parameter is the list[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-114)-- the second, optional unnamed parameter is the list separator (default = comma space)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-115)-- returns the whole list if separator not found[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-116)p.findlast = function(frame)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-117)local s = mw.text.trim( frame.args[1] or "" )[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-118)local sep = frame.args[2] or ""[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-119)if sep == "" then sep = ", " end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-120)local pattern = ".*" .. sep .. "(.*)"[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-121)local a, b, last = s:find(pattern)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-122)if a then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-123)return last[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-124)else[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-125)return s[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-126)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-127)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-128)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-129)-- stripZeros finds the first number and strips leading zeros (apart from units)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-130)-- e.g "0940" -> "940"; "Year: 0023" -> "Year: 23"; "00.12" -> "0.12"[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-131)p.stripZeros = function(frame)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-132)local s = mw.text.trim(frame.args[1] or "")[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-133)local n = tonumber( string.match( s, "%d+" ) ) or ""[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-134)s = string.gsub( s, "%d+", n, 1 )[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-135)return s[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-136)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-137)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-138)-- nowiki ensures that a string of text is treated by the MediaWiki software as just a string[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-139)-- it takes an unnamed parameter and trims whitespace, then removes any wikicode[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-140)p.nowiki = function(frame)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-141)local str = mw.text.trim(frame.args[1] or "")[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-142)return mw.text.nowiki(str)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-143)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-144)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-145)-- split splits text at boundaries specified by separator[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-146)-- and returns the chunk for the index idx (starting at 1)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-147)-- #invoke:String2 |split |text |separator |index |true/false[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-148)-- #invoke:String2 |split |txt=text |sep=separator |idx=index |plain=true/false[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-149)-- if plain is false/no/0 then separator is treated as a Lua pattern - defaults to plain=true[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-150)p.split = function(frame)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-151)local args = frame.args[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-152)if not(args[1] or args.txt) then args = frame:getParent().args end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-153)local txt = args[1] or args.txt or ""[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-154)if txt == "" then return nil end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-155)local sep = (args[2] or args.sep or ""):gsub('"', '')[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-156)local idx = tonumber(args[3] or args.idx) or 1[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-157)local plain = (args[4] or args.plain or "true"):sub(1,1)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-158)plain = (plain ~= "f" and plain ~= "n" and plain ~= "0")[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-159)local splittbl = mw.text.split( txt, sep, plain )[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-160)if idx < 0 then idx = #splittbl + idx + 1 end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-161)return splittbl[idx][](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-162)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-163)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-164)-- val2percent scans through a string, passed as either the first unnamed parameter or |txt=[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-165)-- it converts each number it finds into a percentage and returns the resultant string.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-166)p.val2percent = function(frame)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-167)local args = frame.args[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-168)if not(args[1] or args.txt) then args = frame:getParent().args end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-169)local txt = mw.text.trim(args[1] or args.txt or "")[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-170)if txt == "" then return nil end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-171)local function v2p (x)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-172)x = (tonumber(x) or 0) * 100[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-173)if x == math.floor(x) then x = math.floor(x) end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-174)return x .. "%"[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-175)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-176)txt = txt:gsub("%d[%d%.]*", v2p) -- store just the string[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-177)return txt[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-178)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-179)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-180)-- one2a scans through a string, passed as either the first unnamed parameter or |txt=[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-181)-- it converts each occurrence of 'one ' into either 'a ' or 'an ' and returns the resultant string.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-182)p.one2a = function(frame)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-183)local args = frame.args[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-184)if not(args[1] or args.txt) then args = frame:getParent().args end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-185)local txt = mw.text.trim(args[1] or args.txt or "")[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-186)if txt == "" then return nil end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-187)txt = txt:gsub(" one ", " a "):gsub("^one", "a"):gsub("One ", "A "):gsub("a ([aeiou])", "an %1"):gsub("A ([aeiou])", "An %1")[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-188)return txt[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-189)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-190)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-191)-- findpagetext returns the position of a piece of text in a page[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-192)-- First positional parameter or |text is the search text[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-193)-- Optional parameter |title is the page title, defaults to current page[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-194)-- Optional parameter |plain is either true for plain search (default) or false for Lua pattern search[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-195)-- Optional parameter |nomatch is the return value when no match is found; default is nil[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-196)p._findpagetext = function(args)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-197)-- process parameters[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-198)local nomatch = args.nomatch or ""[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-199)if nomatch == "" then nomatch = nil end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-200)--[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-201)local text = mw.text.trim(args[1] or args.text or "")[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-202)if text == "" then return nil end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-203)--[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-204)local title = args.title or ""[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-205)local titleobj[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-206)if title == "" then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-207)titleobj = mw.title.getCurrentTitle()[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-208)else[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-209)titleobj = mw.title.new(title)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-210)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-211)--[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-212)local plain = args.plain or ""[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-213)if plain:sub(1, 1) == "f" then plain = false else plain = true end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-214)-- get the page content and look for 'text' - return position or nomatch[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-215)local content = titleobj and titleobj:getContent()[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-216)return content and mw.ustring.find(content, text, 1, plain) or nomatch[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-217)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-218)p.findpagetext = function(frame)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-219)local args = frame.args[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-220)local pargs = frame:getParent().args[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-221)for k, v in pairs(pargs) do[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-222)args[k] = v[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-223)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-224)if not (args[1] or args.text) then return nil end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-225)-- just the first value[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-226)return (p._findpagetext(args))[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-227)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-228)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-229)-- returns the decoded url. Inverse of parser function {{urlencode:val|TYPE}}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-230)-- Type is:[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-231)-- QUERY decodes + to space (default)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-232)-- PATH does no extra decoding[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-233)-- WIKI decodes _ to space[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-234)p._urldecode = function(url, type)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-235)url = url or ""[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-236)type = (type == "PATH" or type == "WIKI") and type[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-237)return mw.uri.decode( url, type )[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-238)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-239)-- {{#invoke:String2|urldecode|url=url|type=type}}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-240)p.urldecode = function(frame)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-241)return mw.uri.decode( frame.args.url, frame.args.type )[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-242)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-243)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-244)-- what follows was merged from Module:StringFunc[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-245)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-246)-- helper functions[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-247)p._GetParameters = require('Module:GetParameters')[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-248)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-249)-- Argument list helper function, as per Module:String[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-250)p._getParameters = p._GetParameters.getParameters[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-251)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-252)-- Escape Pattern helper function so that all characters are treated as plain text, as per Module:String[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-253)function p._escapePattern( pattern_str )[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-254)return mw.ustring.gsub( pattern_str, "([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1" )[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-255)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-256)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-257)-- Helper Function to interpret boolean strings, as per Module:String[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-258)p._getBoolean = p._GetParameters.getBoolean[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-259)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-260)--[[[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-261)Strip[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-262)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-263)This function Strips characters from string[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-264)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-265)Usage:[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-266){{#invoke:String2|strip|source_string|characters_to_strip|plain_flag}}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-267)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-268)Parameters[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-269) source: The string to strip[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-270) chars: The pattern or list of characters to strip from string, replaced with ''[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-271) plain: A flag indicating that the chars should be understood as plain text. defaults to true.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-272)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-273)Leading and trailing whitespace is also automatically stripped from the string.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-274)]][](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-275)function p.strip( frame )[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-276)local new_args = p._getParameters( frame.args, {'source', 'chars', 'plain'} )[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-277)local source_str = new_args['source'] or ''[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-278)local chars = new_args['chars'] or '' or 'characters'[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-279)source_str = mw.text.trim(source_str)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-280)if source_str == '' or chars == '' then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-281)return source_str[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-282)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-283)local l_plain = p._getBoolean( new_args['plain'] or true )[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-284)if l_plain then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-285)chars = p._escapePattern( chars )[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-286)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-287)local result[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-288)result = mw.ustring.gsub(source_str, "["..chars.."]", '')[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-289)return result[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-290)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-291)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-292)--[[[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-293)Match any[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-294)Returns the index of the first given pattern to match the input. Patterns must be consecutively numbered.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-295)Returns the empty string if nothing matches for use in {{#if:}}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-296)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-297)Usage:[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-298) {{#invoke:String2|matchAll|source=123 abc|456|abc}} returns '2'.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-299)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-300)Parameters:[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-301) source: the string to search[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-302) plain: A flag indicating that the patterns should be understood as plain text. defaults to true.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-303) 1, 2, 3, ...: the patterns to search for[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-304)]][](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-305)function p.matchAny(frame)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-306)local source_str = frame.args['source'] or error('The source parameter is mandatory.')[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-307)local l_plain = p._getBoolean( frame.args['plain'] or true )[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-308)for i = 1, math.huge do[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-309)local pattern = frame.args[i][](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-310)if not pattern then return '' end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-311)if mw.ustring.find(source_str, pattern, 1, l_plain) then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-312)return tostring(i)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-313)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-314)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-315)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-316)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-317)--[[--------------------------< H Y P H E N _ T O _ D A S H >--------------------------------------------------[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-318)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-319)Converts a hyphen to a dash under certain conditions. The hyphen must separate[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-320)like items; unlike items are returned unmodified. These forms are modified:[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-321) letter - letter (A - B)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-322) digit - digit (4-5)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-323) digit separator digit - digit separator digit (4.1-4.5 or 4-1-4-5)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-324) letterdigit - letterdigit (A1-A5) (an optional separator between letter and[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-325) digit is supported – a.1-a.5 or a-1-a-5)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-326) digitletter - digitletter (5a - 5d) (an optional separator between letter and[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-327) digit is supported – 5.a-5.d or 5-a-5-d)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-328)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-329)any other forms are returned unmodified.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-330)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-331)str may be a comma- or semicolon-separated list[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-332)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-333)]][](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-334)function p.hyphen_to_dash( str, spacing )[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-335)if (str == nil or str == '') then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-336)return str[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-337)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-338)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-339)local accept[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-340)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-341)str = mw.text.decode(str, true )-- replace html entities with their characters; semicolon mucks up the text.split[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-342)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-343)local out = {}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-344)local list = mw.text.split (str, '%s*[,;]%s*')-- split str at comma or semicolon separators if there are any[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-345)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-346)for _, item in ipairs (list) do-- for each item in the list[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-347)item = mw.text.trim(item)-- trim whitespace[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-348)item, accept = item:gsub ('^%(%((.+)%)%)$', '%1')[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-349)if accept == 0 and mw.ustring.match (item, '^%w*[%.%-]?%w+%s*[%-–—]%s*%w*[%.%-]?%w+$') then-- if a hyphenated range or has endash or emdash separators[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-350)if item:match ('^%a+[%.%-]?%d+%s*%-%s*%a+[%.%-]?%d+$') or-- letterdigit hyphen letterdigit (optional separator between letter and digit)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-351)item:match ('^%d+[%.%-]?%a+%s*%-%s*%d+[%.%-]?%a+$') or-- digitletter hyphen digitletter (optional separator between digit and letter)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-352)item:match ('^%d+[%.%-]%d+%s*%-%s*%d+[%.%-]%d+$') or-- digit separator digit hyphen digit separator digit[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-353)item:match ('^%d+%s*%-%s*%d+$') or-- digit hyphen digit[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-354)item:match ('^%a+%s*%-%s*%a+$') then-- letter hyphen letter[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-355)item = item:gsub ('(%w*[%.%-]?%w+)%s*%-%s*(%w*[%.%-]?%w+)', '%1–%2')-- replace hyphen, remove extraneous space characters[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-356)else[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-357)item = mw.ustring.gsub (item, '%s*[–—]%s*', '–')-- for endash or emdash separated ranges, replace em with en, remove extraneous whitespace[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-358)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-359)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-360)table.insert (out, item)-- add the (possibly modified) item to the output table[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-361)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-362)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-363)local temp_str = table.concat (out, ',' .. spacing)-- concatenate the output table into a comma separated string[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-364)temp_str, accept = temp_str:gsub ('^%(%((.+)%)%)$', '%1')-- remove accept-this-as-written markup when it wraps all of concatenated out[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-365)if accept ~= 0 then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-366)temp_str = str:gsub ('^%(%((.+)%)%)$', '%1')-- when global markup removed, return original str; do it this way to suppress boolean second return value[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-367)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-368)return temp_str[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-369)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-370)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-371)function p.hyphen2dash( frame )[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-372)local str = frame.args[1] or ''[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-373)local spacing = frame.args[2] or ' ' -- space is part of the standard separator for normal spacing (but in conjunction with templates r/rp/ran we may need a narrower spacing[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-374)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-375)return p.hyphen_to_dash(str, spacing)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-376)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-377)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-378)-- Similar to [[Module:String#endswith]][](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-379)function p.startswith(frame)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-380)return (frame.args[1]:sub(1, frame.args[2]:len()) == frame.args[2]) and 'yes' or ''[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-381)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-382)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-383)-- Implements [[Template:Isnumeric]][](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-384)function p.isnumeric(frame)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-385)local s = frame.args[1] or frame:getParent().args[1][](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-386)local boolean = (frame.args.boolean or frame:getParent().args.boolean) == 'true'[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-387)if type(s) == 'string' and mw.getContentLanguage():parseFormattedNumber( s ) then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-388)return boolean and 1 or s[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-389)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-390)return boolean and 0 or ''[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-391)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-392)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-393)-- Checks if a value in a group of numbers is not an interger.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-394)-- Allows usage of an |empty= parameter to allow empty values to be skipped.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-395)function p.isInteger(frame)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-396)local values = frame.args or frame:getParent().args[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-397)local allow_empty = frame.args.empty or frame:getParent().args.empty[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-398)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-399)for _, value in ipairs(values) do[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-400)-- Trim spaces[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-401)value = value and value:gsub("^%s*(.-)%s*$", "%1")[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-402)if value == "" or value == nil then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-403)if not allow_empty then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-404)return false -- Empty values are not allowed[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-405)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-406)else[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-407)value = tonumber(value)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-408)if not (type(value) == "number" and value == math.floor(value)) then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-409)return false[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-410)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-411)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-412)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-413)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-414)return true[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-415)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-416)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-417)-- Returns an error found in a string.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-418)function p.getError(frame)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-419)local text = frame.args[1] or frame:getParent().args[1][](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-420)local error_message = text:match('(.-)')[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-421)return error_message or nil[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-422)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-423)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579752&title=Module%3AString2#L-424)return p Retrieved from "[https://freemwiki.com/index.php?title=Module:String2&oldid=579752](https://freemwiki.com/index.php?title=Module:String2&oldid=579752)" [Last edited on 21 October 2025, at 06:18](https://freemwiki.com/index.php?title=Module:String2&action=history) #### Languages This page is not available in other languages. freem * This page was last edited on 21 October 2025, at 06:18. * Content is available under [Creative Commons Attribution-ShareAlike 4.0](https://creativecommons.org/licenses/by-sa/4.0/) unless otherwise noted. FreemWiki is operated by **FINGERPOWER DIGITAL TECHNOLOGY LLC** (Colorado, Entity ID 20221978727). * [Privacy Policy](https://freemwiki.com/wiki/Privacy_Policy) * [About](https://freemwiki.com/wiki/About) * [Terms of Service](https://freemwiki.com/wiki/Terms_of_Service) * [Desktop](https://freemwiki.com/index.php?title=Module:String2&mobileaction=toggle_view_desktop&oldid=579752)