Module:Str find word/doc

This is an old revision of this page, as edited by DePiep (talk | contribs) at 12:35, 14 November 2021. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Module:Str find word/links/doc

This module looks for a complete word in a comma-separated list of words. It then returns a True or False value, which can be used accordingly.

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

For example, in the string 'alpha, foobar' the word 'alpha' appears, but the word 'foo' does not: there only is the complete word 'foobar'. The module is aimed at template code usage. (The editor does not have to apply Lua patterns like [%a%d]*).

A word is defined to be only of these characters: alphanumerics ('a-z A-Z 0-9'), hyphen ('-') and underscore ('_') Green tickY. All other characters are non-word characters, and so possible word-separators (like ';,()<space>' Red X 12pxN).

Usage

Basic

Core function:

{{Str find word
|source =
|word   =
|yes    =
|no     =
}}
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 (''), or the |no= value when entered.
|source= |word= result note
|source=alpha, foo, lima |word=foo foo  Y
|source=alpha, uc-all |word=uc-all uc-all  Y "-" (hyphen) is part of the word
|source=alpha, do_something, white |word=do_something do_something  Y "_" (underscore) is part of the word
|source=alpha, foo, lima |word=november  N
|source=alpha, foobar, lima |word=foo  N 'foo' is not the complete word
|source=alpha, foo, lima |word=  N no |word= entered
|source=alpha, foo, lima |word=foobar No, not found  N full word foo-bar not in the source
|source=alpha, foo, lima |word=foobar No, not found  N word foo not in the source as full word
... |yes=Yes, hit |no=Not found
|source=alpha, foo, lima |word=foo Yes, hit  Y
|source=alpha, foo, lima |word=foobar No, not found  N

All parameters

All parameters, in three options
{{Str find word
|string = 
|word   =
|allwords =
|orwords  = 
|case=
|yes =
|no  =
|explain =
}}
{{Str find word
|s   = 
|w   =
|allw=
|orw =
|case=
|yes =
|no  =
|explain =
}}
{{Str find word |s= |w= |allw= |orw= |case= |yes= |no= |explain=}}

More options

|source=
|s= |1=
|word=
|w= |2=
|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

word list

Instead of a single word to check, a list of target words can be entered: |word=alpha, foo, bingo. This |word=-list will be treated with AND-logic: each and all of the words must be present. See:
Wordlist examples: |word=(wordlist)
|word=alpha, foo
|word=alpha-beta; _bar;all-up#foo(27) Oct Nov [Dec]
When |word= contains a wordlist, all words must be present to return the Yes value (AND-logic).

AND-, OR-wordlist checks

|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=
|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 (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

Roundup

A word
A word can be a-z, A-Z, 0-9, - _ (not: ;,=()[]#$%)
Absent words never can make a True result
Digits are not treated as A number: "12" is a word.
Thus, the digital point "." is a word separato, and so will split "-17.5" into words "-17" and "5".

no numerical treatment: integers only (16.5 -> 16, 5)

newlines are not recognied. (todo: check pipes, etc).
wordlists
Wordlists consist of words & word-separators (=non-word-character): |word=alpha, bravo charlie (17)
Wordlists can be entered in: |source=, |word=, |andwords=, |orwords= and their synonyms |s|w|andw| orw=)
All |word=foo, bar words are treated as AND- words (equally to, and together with |andwords=)
repeated words in a list do not change the result, |word=foo, foo = |word=foo
AND-words: if present, all must be present in the source to be True
OR-words: if present, at least one must be present in the source to be True
An empty wordslist will considered to be True (will not create a False result)
The result to be True requires: AND-check=True and OR-check=True
results
There are no "error" results. If anything logic 'fails', a False value is returned.
By default:
Result=True returns the Yeslist: all words found; the AND-hitlist and the OR-hitlist
By definition, the Yeslist cannot be empty
Each list is , -separated (comma space), between the list is a ;  (semicolon space)
Each list is ordered by their searchlist order: 1. by AND-words 2. by order OR-words (not by order of source-words)
todo example here
Result=False returns a black string

By |yes=|no= parameter

  • When entered, the result will return the |yes= or |no= value for True/False respectively.
|yes=OK, my word is found!; |no=No, my word is not in the source
Each can also be explicitly blank: |no=| (=the default no-return value for False); |yes=|: would require |no=not empty to be meaningful
no nil nor null
there is only T/F result. Not a nil situation.

errors and analysis

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

code