FANDOM


This is a documentation subpage for Template:Remove last word.
It contains usage information, categories and other content that is not part of the original template page.


This template removes the last word of the first parameter, i.e. the last non-space token after the last space. Use |1= for the first parameter if the string may contain an equals sign (=). By default, words are delimited by spaces, but the optional parameter |sep= can set the separator to any character.

Some separators have to be escaped with a percent sign to be accepted, as they are magic characters for Lua patterns: ^$()%.[]*+-?) (see example below and Lua reference on Mediawiki for further details).

Usage

One parameter (space as separator):

  • {{Remove last word|string}}
  • {{Remove last word|1=string}}

Two parameters (user-defined character as separator):

  • {{Remove last word|string|sep=character}}
  • {{Remove last word|1=string|sep=character}}

Examples

Escaping magic characters:

  • {{Remove last word|Nissan GT-R (R35) (upgrades)|sep=%(}} → Nissan GT-R (R35)

Caution: The last space after (R35) is not trimmed. This can lead to unexpected results if used with expressions like {{#ifeq: ...}}.

  • Solution with {{Trim}} to remove leading and trailing spaces:
    {{Trim|{{Remove last word|Text (1) (2)|sep=%(}}}}Next → Text (1)Next

See also


Community content is available under CC-BY-SA unless otherwise noted.