From Wikipedia, the free encyclopedia
This module depends on the following other modules:
Implements template { { Str find word } } .
This module looks for a word being present in a comma-separated list of words. It then returns a True or False value. By default, the True-value returned is the found word itself; the False-value is a blank string.
For example, in the source string 'foo, bar ' the word 'bar ' appears, but the word 'november ' does not.
{{#invoke:Str find word |main |source=foo, bar |word=bar}} (True) → bar
{{#invoke:Str find word |main |source=alpha, beta, gamma |word=november}} (False) →
Multiple word check : The search can be extended to check for multiple words being present.
AND -list of words, all words must be present:
{{#invoke:Str find word |main |source=alpha, beta, gamma |andwords=beta, alpha}} (True) → beta,alpha
{{#invoke:Str find word |main |source=alpha, beta, gamma |andwords=beta, omega}} (False) →
OR -list of words, at least one off the words must be present:
{{#invoke:Str find word |main |source=alpha, beta, gamma |orwords=beta, alpha}} (True) → beta,alpha
{{#invoke:Str find word |main |source=alpha, beta, gamma |orwords=beta, omega}} (False) → beta
Complete words: the complete word is 'foobar ' (example needed)
Whitespace is trimmed,
The module is aimed at template code usage. (The editor does not have to apply Lua patterns like [%a%d]*) .
}}
Main parameters (including their synonyms)
{{Str find word
|source= s=
|word= andwords= andw=
|orwords= orw=
|case=
|out-true=
|out-false=
}}
{{Str find word |s= |w= |andw= |orw= |case= |out-true= |out-false=}}
Basic: word is in source-wordlist ?[ edit ]
{{Str find word
|source =
|word =
}}
{{Str find word |source=cow, horse, dog, fish |word=dog}} (True) → dog
{{Str find word |source=cow, horse, dog, fish |word=cat}} (False) →
True/False return value[ edit ]
When the word is found in the source (True), the function returns the word itself (by default), or | out-true = value (when entered non-empty).
When not found (False), the function returns a empty string (''), or the | out-false = value when entered.
| source = alpha, foo, lima
| word = foo
foo
Y
| source = alpha, foo, lima
| word = bar
N
full word bar not in the source
| source = alpha, foo, lima
| word = foobar
N
word foobar not in the source as full word
AND-wordlist checks [ edit ]
| word = can be a list of words . All will be checked with the AND -requirement (each word must be present).
| andwords = accepts a list of words that all will be checked with the AND -requirement (each word must be present).
Alway, both | word = and | andwords = are combined into one single AND -wordlist.
| source = | s =
| andwords = | word =
result
note
| s = alpha, foo, lima, delta
| andw = delta, lima
delta,lima
both words present in the source
| s = alpha, foo, lima, delta
| andw = foo, nov
AND-logic: A word in the AND -list is not present (nov ), so false
| s = alpha, foo, lima, delta
| andw = delta
delta
| w = and | andw = are combined
| s = alpha, foo, lima, delta
| andw = bar, april
delta
| orwords = , | orw =
Accepts a list of words that all will be checked by the OR-requirement ("at least one of the words must be present).
| source = | s =
| orwords =
result
note
| s = alpha, foo, lima, delta
delta,lima
both words present in the source
| s = alpha, foo, lima, delta
| s = alpha, foo, lima, delta
| andw = delta
delta
| w = and | andw = are combined
| s = alpha, foo, lima, delta
| orw = delta, lima
delta,lima
both OR-words are present in the source
| s = alpha, foo, lima, delta
foo
OR-logic: one of the words is present (| foo = ), so true
| s = alpha, foo, lima, delta
| andw = alpha, lima
| orw = foo, nov
alpha,lima,foo
| s = alpha, foo, lima, delta
| andw = bar, april
| orw = nov, dec
none of the OR-words is present, so false
both AND-words and OR-words to check [ edit ]
| andwords = | orwords =
checks both lists for their own check: "ANd-words" must all be present, "OR-words" must have at least one present.
Result: True if both check results are True, otherwise False.
| source = | s =
| andwords = | word =
| orwords =
result
note
| s = alpha, foo, lima, delta
| andw = delta, lima
delta,lima
both words present in the source
| s = alpha, foo, lima, delta
| andw = foo, nov
AND-logic: A word in the AND -list is not present (nov ), so false
| s = alpha, foo, lima, delta
| andw = delta
delta
| w = and | andw = are combined
| s = alpha, foo, lima, delta
| orw = delta, lima
delta,lima
both OR-words are present in the source
| s = alpha, foo, lima, delta
foo
OR-logic: one of the words is present (| foo = ), so true
| s = alpha, foo, lima, delta
| andw = alpha, lima
| orw = foo, nov
alpha,lima,foo
| s = alpha, foo, lima, delta
| andw = bar, april
| orw = nov, dec
none of the OR-words is present, so false
Blank list(s)
Empty input string(s) will conclude negative:
| source, andwords, orwords = < blank>
| source = < blank>
| word = beta
N
| source = alpha, beta, gamma
| word = < blank>
N
untested; noinclude from main /doc[ edit ]
As of Mar 2023, not supported.
| casesensitive = true, | case = true Case-sensitive (A=/=a) DEFAULT
| casesensitive = false, | case = false Not case-sensitive (A=a)
| source = | s =
| word = | w =
| case =
result
note
| s = alpha, foo, lima
| w = foo
→ foo
| s = alpha, foo, lima
| w = foobar
→
| s = alpha, foobar, lima
| w = foo
→
'foo' is not the complete word
| s = alpha, FOO, lima
| w = foo
→ foo
| case = false: a=A (default)
| s = alpha, FOO, lima
| w = foo
→
| case = true: a=/=A
Rephrase True, False result: | out-true=, out-false = [ edit ]
| out-true = out-true, a hit| out-false = out-falset found
| source = alpha, foo, lima
| word = foo
foo
Y
| source = alpha, foo, lima
| word = foobar
N
| booleans =
| booleans = true will convert all boolean words into "True/False".
per module:Yesno (Yes, true, yes, 1 = true) (todo: document value 2?, nil, blanketc. Irrespective of case?)
other words not changed ("horse" remains horse, not T/F).
Note: per logic definition, the word "false" is returned (as being found).
| booleans = true
| source = YeS
| word = true
true
| source = 0
| word = FalSe
false
note: the word "false" is found and returned
Errors and analysis [ edit ]
The logic itself does not produce errors. There is always a True of False result.
There are no logical errors foreseen: any flaw in the input will return a False result (for example, no input strings to check were entered).
| explain = true: when in Preview , display a report on input, output and the logical steps (debug).
| explain = testcases: When set in ns Template or User on subpage /testcases , the Preview report is static (shown permanently).
String-handling templates
(help page)
Substring (select chunk of string by its position)
{ { str sub new } } Select a substring based on starting and ending index counted in either direction. { { str left } } Keep the first N characters of a string, or duplicate it to N characters. { { str crop } } Return all but the last N characters of a string. { { str index } } Return the N-th character of a string.
{ { str right } } Return substring starting at N-th character to end of string. { { str rightc } } Return the last N characters of a string; or a given value if empty. { { str sub old } } Return substring of given length starting at N-th character.
Trimming (select/remove chunk of string by character type)
Select/remove specific item from string
{ { delink } } , { { trim brackets } } Removes wikilink brackets (wikicode); all or outer only . { { Plain text } } Removes wikicode (formatting and brackets) { { PAGENAMEBASE } } Trim off any parenthesis text at the end of a string (disambiguation). { { title disambig text } } Returns text in parentheses at the end of a string (disambiguation).
{ { title year } } Returns the 3-or-4-digit year from a pagename, if any. { { title decade } } Returns the 4-digit decade from a pagename (e.g. "1740" from "Foo 1740s bar"), if any. { { title number } } Returns any number from a pagename. { { WikiProjectbasename } } Removes "WikiProject" from a pagename.
Insertion, replacement, and length
{ { loop } } Repeat character string a specified number of times. { { replace } } Returns the string, after replacing all occurrences of a specified string with another string. { { str rep } } Returns the string, after replacing the first occurrence of a specified string with another string. { { digits } } Returns the string, after removing all characters that are not digits 0–9 { { Nowiki } } Displays wikitext as plain text.
{ { str len } } Returns a string's length. { { str ≥ len } } Check if a string is "longer or equally long" or "shorter" than a given length. { { str ≤ len } } Check if a string is "shorter or equally long" or "longer" than a given length. { { str ≠ len } } Check if a string is "not equal" or "equal" to a given length.
Analysis and searching
{ { Array } } Array item manipulation and retrieval. { { a or an } } Takes a noun and produces the appropriate indefinite article, based on whether the first letter is a vowel. { { in string } } Returns optional string when given string is not found { { Isnumeric } } Returns number when true, blank when not numeric. { { str letter } } Returns the number of letters that begin a string. { { str number } } Returns the number of numbers that begin a string.
Modules and built-in functions