Module:Str find word/doc

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

§ code

Module:String  ·  :Module:TableTools
mw:Lua manual  · User:DePiep/sfw (/sandbox)
====basic tests====
  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".
====yes no options====
  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".
====E0x input====
  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".
  • Script error: No such module "User:DePiep/sfw".

{Module rating|pre-alpha}}

Module:check for unknown parameters

This module is intended to find complete words in a string. It returns a True or False value, which can be used accordingly. 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).

Word examples todo check+good examples
foo, foobar, foo-bar foo_bar#)($foo123   Foo. FOO..._foo] 12, -x, zob(28)
foo, foobar, foo-bar foo_bar#)($foo123   Foo. FOO..._foo] [12, -x
foo, foobar, foo-bar foo_bar#)($foo123   Foo. FOO..._foo] [12, -x

For example: your template can use your predefined options as single parameter |format= input:

|format=bg-green, uc_first, wikilink

The template then can handle formatting like this:

{{#invoke:sfw|main|source={{{format|}}}|word=bg-green |yes=<make bg green code> |no=<do nothing>}}
{{#invoke:sfw|main|source={{{format|}}}|word=uc_first |yes=<set uc first code> |no=<do nothing>}}

Or, using the default output:

{{#if:{{#invoke:sfw|main|source={{{format|}}}|word=bg-green}} |<make bg green code> |<do nothing>}}
{{#if:{{#invoke:sfw|main|source={{{format|}}}|word=uc_first}} |<set uc first code> |<do nothing>}}

Usage

Basic

Core function:

{{User:DePiep/sfw
|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 Script error: No such module "User:DePiep/sfw".  Y
|source=alpha, uc-all |word=uc-all Script error: No such module "User:DePiep/sfw".  Y "-" (hyphen) is part of the word
|source=alpha, do_something, white |word=do_something Script error: No such module "User:DePiep/sfw".  Y "_" (underscore) is part of the word
|source=alpha, foo, lima |word=november Script error: No such module "User:DePiep/sfw".  N
|source=alpha, foobar, lima |word=foo Script error: No such module "User:DePiep/sfw".  N 'foo' is not the complete word
|source=alpha, foo, lima |word= Script error: No such module "User:DePiep/sfw".  N no |word= entered
|source=alpha, foo, lima |word=foobar Script error: No such module "User:DePiep/sfw".  N full word foo-bar not in the source
|source=alpha, foo, lima |word=foobar Script error: No such module "User:DePiep/sfw".  N word foo not in the source as full word
... |yes=Yes, hit |no=Not found
|source=alpha, foo, lima |word=foo Script error: No such module "User:DePiep/sfw".  Y
|source=alpha, foo, lima |word=foobar Script error: No such module "User:DePiep/sfw".  N

All parameters

All parameters, in three options
{{User:DePiep/sfw
|string = 
|word   =
|allwords =
|orwords  = 
|case=
|yes =
|no  =
}}
{{User:DePiep/sfw
|s   = 
|w   =
|allw=
|orw =
|case=
|yes =
|no  =
}}
{{User:DePiep/sfw
|    = 
|    =
|allw=
|orw =
|case=
|yes =
|no  =
}}
{{User:DePiep/sfw |s= |w= |allw= |orw= |case= |yes= |no= }}

More options

|source=
|s= |1=
|word=
|w= |2=
|case= result note
|s=alpha, foo, lima |w=foo Script error: No such module "User:DePiep/sfw".
|s=alpha, foo, lima |w=foobar Script error: No such module "User:DePiep/sfw".
|s=alpha, foobar, lima |w=foo Script error: No such module "User:DePiep/sfw". 'foo' is not the complete word
|s=alpha, FOO, lima |w=foo Script error: No such module "User:DePiep/sfw". |case=false: a=A (default)
|s=alpha, FOO, lima |w=foo Script error: No such module "User:DePiep/sfw". |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 Script error: No such module "User:DePiep/sfw". both words present in the source
|s=alpha, foo, lima, delta |andw=foo, nov Script error: No such module "User:DePiep/sfw". AND-logic: A word in the AND-list is not present (nov), so false
|s=alpha, foo, lima, delta |andw=delta Script error: No such module "User:DePiep/sfw". |w= and |andw= are combined
|s=alpha, foo, lima, delta |orw=delta, lima Script error: No such module "User:DePiep/sfw". both OR-words are present in the source
|s=alpha, foo, lima, delta Script error: No such module "User:DePiep/sfw". OR-logic: one of the words is present (|foo=), so true
|s=alpha, foo, lima, delta |andw=alpha, lima |orw=foo, nov Script error: No such module "User:DePiep/sfw".
|s=alpha, foo, lima, delta |andw=bar, april |orw=nov, dec Script error: No such module "User:DePiep/sfw". none of the OR-words is present, so false

Roundup

A word can be a-z, A-Z, 0-9, - _ (not: ;,=()[]#$%)
Absent words never can make a positive
All |word=foo, bar words are treated as AND- words (equally to, and together with |andwords=)
AND-word must all be present in the source
OR-words require that at least one is present in the source
|yes= cannot be empty (a True result will return either your |yes=vaue or, by default, the yes-words found
There are no "error" results. If anything fails, it's a No.

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