This is the documentation page for Module:Str find word

TOC: #code (edit)

Template:Lua This module looks for a word being present in a comma-separated list of words. It then returns a Template:Code or Template:Code value. By default, the True-value returned is the found word itself; the False-value is a blank string. Implements {{Str find word}}.

For example, in the source string 'Template:Mono' the word 'Template:Mono' appears, but the word 'Template:Mono' does not.

True: {{#invoke:Str find word|main |source=foo, bar|word=bar}} → >bar<
False: {{#invoke:Str find word|main |source=alpha, beta, gamma|word=november}} → ><

Complete words: the complete word is 'Template:Mono' ... example needed ...

Multiple word check: The search can be extended to check for multiple words being present.

AND-list of words, all words must be present:

True: {{#invoke:Str find word|main |source=alpha, beta, gamma|andwords=beta, alpha}} → >beta,alpha<
False: {{#invoke:Str find word|main |source=alpha, beta, gamma|andwords=beta, omega}} → ><

OR-list of words, at least one off the words must be present:

True: {{#invoke:Str find word|main |source=alpha, beta, gamma|orwords=beta, alpha}} → >beta,alpha<
False: {{#invoke:Str find word|main |source=alpha, beta, gamma|orwords=beta, omega}} → >beta<

The module is aimed at template code usage. (The editor does not have to apply Lua patterns like Template:Code).

UsageEdit

Template:Red. See template {{Str find word}}.

ParametersEdit

All parameters (synonyms)
{{Str find word
|string = 
|word   =
|orwords  = 
|case=
|yes =
|no  =
|explain =
}}
{{Str find word
|s   = 
|w   =
|orw =
|case=
|yes =
|no  =
|explain =
}}
{{Str find word
|s= source= 
|word= andwords= andw=
|orwords= orw=
|case=
|yes=
|no=
|explain=
<!-- |sep=todo -->
}}
{{Str find word |s= |w= |andw= |orw= |case= |yes= |no= |explain=}}

Basic: source, wordEdit

{{Str find word
|source =
|word   =
}}
When the word is found in the source (True), the function returns the word itself (by default), or |yes= value (when entered non-empty).
When not found (False), the function returns a empty string (Template:Code), or the |no= value when entered.
|source=alpha, foo, lima |word=foo foo Template:Aye
|source=alpha, foo, lima |word=bar Template:Nay full word bar not in the source
|source=alpha, foo, lima |word=foobar Template:Nay word foobar not in the source as full word

Case, Literal,Edit

todo: examplify
|source=
|s=
|word=
|w=
|case= result note
|s=alpha, foo, lima |w=foo → yes
|s=alpha, foo, lima |w=foobar → no
|s=alpha, foobar, lima |w=foo → no 'foo' is not the complete word
|s=alpha, FOO, lima |w=foo → yes |case=false: a=A (default)
|s=alpha, FOO, lima |w=foo → no |case=true: a=/=A

AND-, OR-wordlist checksEdit

|word= as noted, 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).
When both |word=, |andwords= are present, they are combined into one single AND-wordlist.
|orwords= accepts a list of words that all will be checked with the OR-requirement (at least one of the words must be present).
|source=
|s=
|andwords=, |andw=
|word=
|w=
|orwords=
|orw=
result TODO fix 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 (Template:Mono), 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

True, False rephrase options |yes, no=Edit

Template:Code |yes=Yes, hit |no=Not found
|source=alpha, foo, lima |word=foo Yes, hit Template:Aye
|source=alpha, foo, lima |word=foobar No, not found Template:Nay

Edge cases: (blank input,)Edit

todo

issues and ideasEdit

  • Keep the order, Foo, bar -> foo(1), bar(2)
eg table col userinput options, then cols in that order?
  • Check comma example above (Template:Code) (currently returns: 2 hitwords & sep=comma Dec2022)
and resolve Template:Code
  • option |sep= for output list >, < dflt

Errors and analysisEdit

  • 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).

codeEdit