Template:Posnq/doc

From imedwiki
< Template:Posnq
Jump to navigation Jump to search

Wrapper template for function posnq in Module:String2.

  • posnq (position, no quotes) returns the numerical start position of the first occurrence of one piece of text ("target") inside another ("source"). UTC characters are supported.
  • It returns nil by default if no match is found, or if either parameter is blank. If no match is found it can return the value of an optional "nomatch" parameter.
  • It takes the text to be searched in as the first unnamed parameter (or |source=), which is trimmed.
  • It takes the text to match as the second unnamed parameter (or |target=), which is trimmed and any double quotes " are stripped out. That allows spaces at the beginning or end of the match string to be included in a consistent manner.
  • It can take an optional third unnamed parameter (or |plain=), which is trimmed. If it's set to false, then the search accepts Lua pattern-matching for the target, otherwise a plain search is used.
  • It can take an optional fourth unnamed parameter (or |nomatch=), which is trimmed. This value is returned if no match occurs. Setting |nomatch=0 makes the output compatible with the find function in Module:String.

Examples

  • {{Posnq |This is a piece of text to be searched |piece of }}

11

  • {{Posnq |This is a piece oftext to be searched |piece of }}

11

  • {{Posnq |This is a piece of text to be searched |"piece of "}}

11

  • {{Posnq |This is a piece oftext to be searched |"piece of "}}
  • {{posnq |This is a piece of text to be searched |ext}}

21

  • {{posnq |This is a piece of text to be searched |ent}}
  • {{posnq |This is a piece of text to be searched |" pie"}}

10

  • {{posnq |This is a piece of text to be searched |" ece"}}

13

  • {{posnq |source=This is a piece of text |target=%s |plain=true}}
  • {{posnq |source=This is a piece of text |target=%s |plain=false}}

5

  • {{posnq |source=This is a piece of text |target=ece |nomatch=0}}

13

  • {{posnq |source=This is a piece of text |target=xyz |nomatch=0}}

0

16

0

10


This template is based (in parts) on the Template:Posnq/doc from the free encyclopedia wikipedia and is licensed under GNU license for free documentation and the Creative Commons Attribution/Share Alike. On wikipedia there is a List of authors accessible. More about importing from wikipedia on page Imedwiki:Importing from wikipedia.