Module:Str find word
![]() | 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
) → Script error: The module returned a nil value. It is supposed to return an export table.{{#invoke:Str find word |main |source=alpha, beta, gamma |word=november}}
(False
) → Script error: The module returned a nil value. It is supposed to return an export table.
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
) → Script error: The module returned a nil value. It is supposed to return an export table.{{#invoke:Str find word |main |source=alpha, beta, gamma |andwords=beta, omega}}
(False
) → Script error: The module returned a nil value. It is supposed to return an export table.
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
) → Script error: The module returned a nil value. It is supposed to return an export table.{{#invoke:Str find word |main |source=alpha, beta, gamma |orwords=beta, omega}}
(False
) → Script error: The module returned a nil value. It is supposed to return an export table.
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]*
).
}}
Parameters
- 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?
{{Str find word |source = |word = }}
{{Str find word |source=cow, horse, dog, fish |word=dog}}
(True
) → Script error: The module returned a nil value. It is supposed to return an export table.{{Str find word |source=cow, horse, dog, fish |word=cat}}
(False
) → Script error: The module returned a nil value. It is supposed to return an export table.
True/False return value
- 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
|
Script error: The module returned a nil value. It is supposed to return an export table. | ![]() |
|
|source=alpha, foo, lima
|
|word=bar
|
Script error: The module returned a nil value. It is supposed to return an export table. | ![]() |
full word bar not in the source |
|source=alpha, foo, lima
|
|word=foobar
|
Script error: The module returned a nil value. It is supposed to return an export table. | ![]() |
word foobar not in the source as full word |
AND-wordlist checks
|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
|
Script error: The module returned a nil value. It is supposed to return an export table. | both words present in the source |
|s=alpha, foo, lima, delta
|
|andw=foo, nov
|
Script error: The module returned a nil value. It is supposed to return an export table. | AND-logic: A word in the AND-list is not present (nov), so false |
|s=alpha, foo, lima, delta
|
|andw=delta
|
Script error: The module returned a nil value. It is supposed to return an export table. | |w= and |andw= are combined
|
|s=alpha, foo, lima, delta
|
|andw=bar, april
|
Script error: The module returned a nil value. It is supposed to return an export table. |
OR-wordlist checks
|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
|
Script error: The module returned a nil value. It is supposed to return an export table. | both words present in the source | ||
|s=alpha, foo, lima, delta
|
Script error: The module returned a nil value. It is supposed to return an export table. | |||
|s=alpha, foo, lima, delta
|
|andw=delta
|
Script error: The module returned a nil value. It is supposed to return an export table. | |w= and |andw= are combined
| |
|s=alpha, foo, lima, delta
|
|orw=delta, lima
|
Script error: The module returned a nil value. It is supposed to return an export table. | both OR-words are present in the source | |
|s=alpha, foo, lima, delta
|
Script error: The module returned a nil value. It is supposed to return an export table. | OR-logic: one of the words is present (|foo= ), so true
| ||
|s=alpha, foo, lima, delta
|
|andw=alpha, lima
|
|orw=foo, nov
|
Script error: The module returned a nil value. It is supposed to return an export table. | |
|s=alpha, foo, lima, delta
|
|andw=bar, april
|
|orw=nov, dec
|
Script error: The module returned a nil value. It is supposed to return an export table. | none of the OR-words is present, so false |
both AND-words and OR-words to check
|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
|
Script error: The module returned a nil value. It is supposed to return an export table. | both words present in the source | |
|s=alpha, foo, lima, delta
|
|andw=foo, nov
|
Script error: The module returned a nil value. It is supposed to return an export table. | AND-logic: A word in the AND-list is not present (nov), so false | |
|s=alpha, foo, lima, delta
|
|andw=delta
|
Script error: The module returned a nil value. It is supposed to return an export table. | |w= and |andw= are combined
| |
|s=alpha, foo, lima, delta
|
|orw=delta, lima
|
Script error: The module returned a nil value. It is supposed to return an export table. | both OR-words are present in the source | |
|s=alpha, foo, lima, delta
|
Script error: The module returned a nil value. It is supposed to return an export table. | OR-logic: one of the words is present (|foo= ), so true
| ||
|s=alpha, foo, lima, delta
|
|andw=alpha, lima
|
|orw=foo, nov
|
Script error: The module returned a nil value. It is supposed to return an export table. | |
|s=alpha, foo, lima, delta
|
|andw=bar, april
|
|orw=nov, dec
|
Script error: The module returned a nil value. It is supposed to return an export table. | none of the OR-words is present, so false |
Edge cases
- Blank list(s)
- Empty input string(s) will conclude negative:
|source, andwords, orwords=<blank>
| ||||
---|---|---|---|---|
|source=<blank>
|
|word=beta
|
Script error: The module returned a nil value. It is supposed to return an export table. | ![]() | |
|source=alpha, beta, gamma
|
|word=<blank>
|
Script error: The module returned a nil value. It is supposed to return an export table. | ![]() |
Errors and analysis
- The logic itself does not produce errors. There is always a True of False result.
- Pages with Unknown parameters are listed in Category:Pages using str find word with unknown parameters (0).
- 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).