Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Humanipedia
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Module:Str find word/doc
Module
Discussion
English
Read
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Lua|Module:String|Module:TableTools|Module:Yesno}} Implements template '''{{tl|Str find word}}'''. This module looks for a word being present in a comma-separated list of words. It then returns a {{code|1=True}} or {{code|1=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 '{{mono|1=foo, bar}}' the word '{{mono|1=bar}}' appears, but the word '{{mono|1=november}}' does not. :<code><nowiki>{{#invoke:Str find word |main |source=foo, bar |word=bar}}</nowiki></code> <small>({{code|1=True}})</small> → {{#invoke:Str find word |main |source=foo, bar |word=bar}} :<code><nowiki>{{#invoke:Str find word |main |source=alpha, beta, gamma |word=november}}</nowiki></code> <small>({{code|1=False}})</small> → {{#invoke:Str find word |main |source=alpha, beta, gamma |word=november}} ''Multiple word check'': The search can be extended to check for multiple words being present. ''AND''-list of words, all words must be present: :<code><nowiki>{{#invoke:Str find word |main |source=alpha, beta, gamma |andwords=beta, alpha}}</nowiki></code> <small>({{code|1=True}})</small> → {{#invoke:Str find word |main |source=alpha, beta, gamma |andwords=beta, alpha}} :<code><nowiki>{{#invoke:Str find word |main |source=alpha, beta, gamma |andwords=beta, omega}}</nowiki></code> <small>({{code|1=False}})</small> → {{#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: :<code><nowiki>{{#invoke:Str find word |main |source=alpha, beta, gamma |orwords=beta, alpha}}</nowiki></code> <small>({{code|1=True}})</small> → {{#invoke:Str find word |main |source=alpha, beta, gamma |orwords=beta, alpha}} :<code><nowiki>{{#invoke:Str find word |main |source=alpha, beta, gamma |orwords=beta, omega}}</nowiki></code> <small>({{code|1=False}})</small> → {{#invoke:Str find word |main |source=alpha, beta, gamma |orwords=beta, omega}} Complete words: the complete word is '{{mono|1=foobar}}' (example needed) Whitespace is trimmed, The module is aimed at template code usage. <small>(The editor does not have to apply Lua patterns like {{code|1=[%a%d]*}})</small>. }} ==Parameters== :Main parameters (including their synonyms) {| |<pre> {{Str find word |source= s= |word= andwords= andw= |orwords= orw= |case= |out-true= |out-false= }} </pre> |} <pre>{{Str find word |s= |w= |andw= |orw= |case= |out-true= |out-false=}}</pre> ===Basic: ''word'' is in ''source-wordlist''?=== <pre> {{Str find word |source = |word = }} </pre> :<code><nowiki>{{Str find word |source=cow, horse, dog, fish |word=dog}}</nowiki></code> <small>({{code|1=True}})</small> → {{Str find word |source=cow, horse, dog, fish |word=dog}} :<code><nowiki>{{Str find word |source=cow, horse, dog, fish |word=cat}}</nowiki></code> <small>({{code|1=False}})</small> → {{Str find word |source=cow, horse, dog, fish |word=cat}} ===True/False return value=== :When the ''word'' is found in the ''source'' (True), the function returns the ''word'' itself (by default), or {{para|out-true}} value (when entered non-empty). :When not found (False), the function returns a empty string ({{code|''}}), or the {{para|out-false}} value when entered. {| class="wikitable" |- | {{para|1=source|2=alpha, foo, lima}} | {{para|word|foo}} | {{#invoke:Str find word |main |explain=true |source=alpha, foo, lima |word=foo}} | {{aye}} | |- | {{para|1=source|2=alpha, foo, lima}} | {{para|word|bar}} | {{#invoke:Str find word |main |explain=true |source=alpha, foo, lima |word=foo-bar}} | {{nay}} | full word ''bar'' not in the source |- | {{para|1=source|2=alpha, foo, lima}} | {{para|word|foobar}} | {{#invoke:Str find word |main |explain=true |source=alpha, foo, lima}} | {{nay}} | word ''foobar'' not in the source as full word |} ===AND-wordlist checks=== :{{para|word}} can be a ''list of words''. All will be checked with the ''AND''-requirement (each word must be present). :{{para |andwords}} accepts a ''list of words'' that all will be checked with the ''AND''-requirement (each word must be present). :Alway, ''both'' {{para|word}} and {{para |andwords}} are combined into one single ''AND''-wordlist. {| class="wikitable" style="" |- ! {{para|1=source}}<br/>{{para|1=s}} ! {{para|1=andwords}}<br/>{{para|1=word}} ! result ! note |- | {{para|1=s|2=alpha, foo, lima, delta}} | {{para |andw|delta, lima}} | {{#invoke:Str find word |main |explain=true |s=alpha, foo, lima, delta |andw=delta, lima}} | both words present in the source |- | {{para|1=s|2=alpha, foo, lima, delta}} | {{para |andw|foo, nov}} | {{#invoke:Str find word |main |explain=true |s=alpha, foo, lima, delta}} | AND-logic: A word in the ''AND''-list is not present ({{mono|nov}}), so false |- | {{para|1=s|2=alpha, foo, lima, delta}} | {{para |andw|delta}} | {{#invoke:Str find word |main |explain=true |s=alpha, foo, lima, delta |andw=delta}} | {{para|w}} and {{para |andw}} are combined |- | {{para|1=s|2=alpha, foo, lima, delta}} | {{para |andw|bar, april}} | {{#invoke:Str find word |main |explain=true |s=alpha, foo, lima, delta |andw=delta}} | |} ===OR-wordlist checks=== ;{{para |orwords}}, {{para |orw}} :Accepts a ''list of words'' that all will be checked by the ''OR-requirement'' ("at least one of the words must be present). {| class="wikitable" style="" |- ! {{para|1=source}}<br/>{{para|1=s}} ! ! {{para|1=orwords}} ! result ! note |- | {{para|1=s|2=alpha, foo, lima, delta}} | | | {{#invoke:Str find word |main |explain=true |s=alpha, foo, lima, delta |andw=delta, lima}} | both words present in the source |- | {{para|1=s|2=alpha, foo, lima, delta}} | | | {{#invoke:Str find word |main |explain=true |s=alpha, foo, lima, delta}} | |- | {{para|1=s|2=alpha, foo, lima, delta}} | {{para |andw|delta}} | | {{#invoke:Str find word |main |explain=true |s=alpha, foo, lima, delta |andw=delta}} | {{para|w}} and {{para |andw}} are combined |- | {{para|1=s|2=alpha, foo, lima, delta}} | | {{para |orw|delta, lima}} | {{#invoke:Str find word |main |explain=true |s=alpha, foo, lima, delta |orw=delta, lima}} | both OR-words are present in the source |- | {{para|1=s|2=alpha, foo, lima, delta}} | | | {{#invoke:Str find word |main |explain=true |s=alpha, foo, lima, delta |orw=foo, nov}} | OR-logic: one of the words is present ({{para|foo}}), so true |- | {{para|1=s|2=alpha, foo, lima, delta}} | {{para |andw|alpha, lima}} | {{para |orw|foo, nov}} | {{#invoke:Str find word |main |explain=true |s=alpha, foo, lima, delta |andw=alpha, lima |orw=foo, nov}} | |- | {{para|1=s|2=alpha, foo, lima, delta}} | {{para |andw|bar, april}} | {{para |orw|nov, dec}} | {{#invoke:Str find word |main |explain=true |s=alpha, foo, lima, delta |andw=delta |orw=nov, dec}} | none of the OR-words is present, so false |} ===both AND-words and OR-words to check=== ;{{para |andwords}} {{para |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. {| class="wikitable" style="" |- ! {{para|1=source}}<br/>{{para|1=s}} ! {{para|1=andwords}}<br/>{{para|1=word}} ! {{para|1=orwords}} ! result ! note |- | {{para|1=s|2=alpha, foo, lima, delta}} | {{para |andw|delta, lima}} | | {{#invoke:Str find word |main |explain=true |s=alpha, foo, lima, delta |andw=delta, lima}} | both words present in the source |- | {{para|1=s|2=alpha, foo, lima, delta}} | {{para |andw|foo, nov}} | | {{#invoke:Str find word |main |explain=true |s=alpha, foo, lima, delta}} | AND-logic: A word in the ''AND''-list is not present ({{mono|nov}}), so false |- | {{para|1=s|2=alpha, foo, lima, delta}} | {{para |andw|delta}} | | {{#invoke:Str find word |main |explain=true |s=alpha, foo, lima, delta |andw=delta}} | {{para|w}} and {{para |andw}} are combined |- | {{para|1=s|2=alpha, foo, lima, delta}} | | {{para |orw|delta, lima}} | {{#invoke:Str find word |main |explain=true |s=alpha, foo, lima, delta |orw=delta, lima}} | both OR-words are present in the source |- | {{para|1=s|2=alpha, foo, lima, delta}} | | | {{#invoke:Str find word |main |explain=true |s=alpha, foo, lima, delta |orw=foo, nov}} | OR-logic: one of the words is present ({{para|foo}}), so true |- | {{para|1=s|2=alpha, foo, lima, delta}} | {{para |andw|alpha, lima}} | {{para |orw|foo, nov}} | {{#invoke:Str find word |main |explain=true |s=alpha, foo, lima, delta |andw=alpha, lima |orw=foo, nov}} | |- | {{para|1=s|2=alpha, foo, lima, delta}} | {{para |andw|bar, april}} | {{para |orw|nov, dec}} | {{#invoke:Str find word |main |explain=true |s=alpha, foo, lima, delta |andw=delta |orw=nov, dec}} | none of the OR-words is present, so false |} ===Edge cases === ;Blank list(s) :Empty input string(s) will conclude negative: {| class="wikitable" |- ! colspan="5" style="padding-left:3em; text-align:left;" | {{para|1=source, andwords, orwords|2=<blank>}} |- | {{para|1=source|2=<blank>}} | {{para|word|beta}} | {{#invoke:Str find word |main |source= |word=beta}} | {{nay}} |- | {{para|1=source|2=alpha, beta, gamma}} | {{para|word|<blank>}} | {{#invoke:Str find word |main |alpha, beta, gamma |word=}} | {{nay}} |} <noinclude> ==untested; noinclude from main /doc== :As of Mar 2023, not supported. ===casesensitive === :{{para|casesensitive|true}}, {{para|case|true}} Case-sensistive (A=/=a) DEFAULT :{{para|casesensitive|false}}, {{para|case|false}} Not case-sensistive (A=a) {| class="wikitable" style="" |- ! {{para|1=source}}<br/> {{para|1=s}} ! {{para|1=word}}<br/>{{para|1=w}} ! {{para|1=case}} ! result ! note |- | {{para|1=s|2=alpha, foo, lima}} | {{para|w|foo}} | | → {{#invoke:Str find word |main |explain=true |s=alpha, foo, lima|w=foo|out-true=yes|out-false=no}} | |- | {{para|1=s|2=alpha, foo, lima}} | {{para|w|foobar}} | | → {{#invoke:Str find word |main |explain=true |source=alpha, foo, lima |word=foobar|out-true=yes|out-false=no}} | |- | {{para|1=s|2=alpha, foobar, lima}} | {{para|w|foo}} | | → {{#invoke:Str find word |main |explain=true |source=alpha, foobar, lima |word=foo|out-true=yes|out-false=no}} | 'foo' is not the complete word |- | {{para|1=s|2=alpha, FOO, lima}} | {{para|w|foo}} | | → {{#invoke:Str find word |main |explain=true |source=alpha, FOO, lima |word=foo|out-true=yes|out-false=no|case=false}} | {{para|case|false}}: a=A ''(default)'' |- | {{para|1=s|2=alpha, FOO, lima}} | {{para|w|foo}} | | → {{#invoke:Str find word |main |explain=true |source=alpha, FOO, lima |word=foo|out-true=yes|out-false=no|case=true}} | {{para|case|true}}: a=/=A |} ===Rephrase True, False result: {{para|1=out-true=, out-false|2=}}=== {| class="wikitable" |- ! colspan="5" style="padding-left:3em; text-align:left;" | {{para|out-true|out-true, a hit}}<br/>{{para|out-false|out-falset found}} |- | {{para|1=source|2=alpha, foo, lima}} | {{para|word|foo}} | {{#invoke:Str find word |main |explain=true |source=alpha, foo, lima |word=foo|out-true=Yes, a hit|out-false=No, not found}} | {{aye}} |- | {{para|1=source|2=alpha, foo, lima}} | {{para|word|foobar}} | {{#invoke:Str find word |main |explain=true |source=alpha, foo, lima |word=foobar|out-true=Yes, a hit|out-false=No, not found}} | {{nay}} |} ===boolean words=== ;{{para|booleans}} :{{para|booleans|true}} will convert ''all boolean words'' into "True/False". :per [[:module:Yesno]] ({{code|1=Yes, true, yes, 1}} = true) (todo: document value 2?, nil, blanketc. Irrespective of case?) :other words not changed ("horse" remains horse, not T/F). :Note: per logic definition, the ''word'' "false" is returned (as being found). {| class="wikitable" |- ! colspan="5" style="padding-left:3em; text-align:left;" | {{para|1=booleans|2=true}} |- | {{para|1=source|2=YeS}} | {{para|1=word|2=true}} | {{#invoke:Str find word |main |booleans=true |source=YeS |word=1}} | |- | {{para|1=source|2=0}} | {{para|1=word|2=FalSe}} | {{#invoke:Str find word |main |booleans=true |source=0 |word=FalSe}} | ''note:'' the ''word'' "false" is found and returned |} ===quotes, escape=== :under construction ===synonyms=== :under construction </noinclude> ==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 {{clc|Category:Pages using str find word with unknown parameters}}. :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). * {{para|explain|true}}: when in {{button|Preview}}, display a report on input, output and the logical steps (debug). * {{para|explain|testcases}}: When set in ns {{mono|1=Template}} or {{mono|1=User}} on subpage {{mono|1=/testcases}}, the Preview report is static (shown permanently). {{String-handling templates|state=collapsed}} <includeonly>{{sandbox other|| [[:Category:Modules that manipulate strings]] }}</includeonly>
Summary:
Please note that all contributions to Humanipedia may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Humanipedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Aligned table
(
edit
)
Template:Aye
(
edit
)
Template:Button
(
edit
)
Template:Category link with count
(
edit
)
Template:Clc
(
edit
)
Template:Code
(
edit
)
Template:Div col
(
edit
)
Template:Div col/styles.css
(
edit
)
Template:Div col end
(
edit
)
Template:Hlist/styles.css
(
edit
)
Template:Ifsubst
(
edit
)
Template:Lua
(
edit
)
Template:Main other
(
edit
)
Template:Mono
(
edit
)
Template:Mono/styles.css
(
edit
)
Template:Nay
(
edit
)
Template:Para
(
edit
)
Template:Plainlist/styles.css
(
edit
)
Template:Str find word
(
edit
)
Template:String-handling templates
(
edit
)
Template:Template link
(
edit
)
Template:Tl
(
edit
)
Module:Arguments
(
edit
)
Module:Check for unknown parameters
(
edit
)
Module:Lua banner
(
edit
)
Module:Navbar
(
edit
)
Module:Navbar/configuration
(
edit
)
Module:Navbar/styles.css
(
edit
)
Module:Navbox
(
edit
)
Module:Navbox/configuration
(
edit
)
Module:Navbox/styles.css
(
edit
)
Module:Navbox with collapsible groups
(
edit
)
Module:Str find word
(
edit
)
Module:String
(
edit
)
Module:TableTools
(
edit
)