Module:Str find word/doc

This is an old revision of this page, as edited by DePiep (talk | contribs) at 21:23, 30 September 2021. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Module:String#find
mw:Extension:Scribunto/Lua_reference_manual#Patterns
User:DePiep/sfw
User:DePiep/sfw/sandbox

This module is intended to find complete words in a string. For example, in the string 'alpha, foobar' the word 'alpha' appears, but the word 'foo' does not: there only is the complete word 'foobar'.

A word is defined to be consisting of: alphanumerics (a-z, A-Z, 0-9), the hyphen (-) and the underscore (_). For example: foobar, foo-bar, foo_bar, foo123, Foo, FOO, _foo, 12, -x. All other characters are non-word characters (', ; ( ) <space>').

The module is designed for template code usage. For example, your template uses this format options as single parameter input:

|format=bg-green, ucfirst, wikilink

Then you can handle formatting:

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

(The alternative is to encode and use three parameters: |bg=green, |case=ucfirst, |link=wikilink).

All this is more article-editor-friendly (one parameter, and type the word). Also, you have the "and" & "or" option (see below).

Usage

Basic parameters are

|source =
|word   =
|yes    =
|no     =
|source= or |s=: long source string to search in
|word= or |w=: word to search for
|yes=: return value when word is found
|no=: return value when word is not foound
|source= |word= result note
|source=alpha, foo, lima |word=foo Script error: No such module "User:DePiep/sfw".

parameters

{{#invoke|main|
|source = 
|word =
|andwords =
|orwords  =
|case = 
|yes =
|no  =
|dbg =
}}
{{#invoke|main|
|s = 
|w =
|andw =
|orw  =
|case =
|yes =
|no  =
|dbg =
}}
{{#invoke|main|
|1 = 
|2 =
|3 =
|4 =
|5 = 
|6 =
|7 =
|8 =
}}