Template:FormatAlias

From Timescape Wiki
Revision as of 19:25, 18 August 2024 by Lord Durok (talk | contribs) (Created page with "<includeonly>{{#if:{{#pos:{{{1|}}}|/}}|{{#rreplace:{{{1}}}|([\w\.[:blank:]\[\]]+)\/([\w\.[:blank:]\[\]]+)|$1 (as $2)}}|{{{1|}}}}}</includeonly><noinclude>This template takes a comma-separated string of names and looks for aliases that are set off by a forward slash (<code>"/"</code>), such as <code>Dale Henson/slade</code>. If found, the names are formatted like so: <code>Dale Henson (as slade)</code>. Either name (or both) may be wikilinked. If no slash is found, the ar...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This template takes a comma-separated string of names and looks for aliases that are set off by a forward slash ("/"), such as Dale Henson/slade. If found, the names are formatted like so: Dale Henson (as slade). Either name (or both) may be wikilinked. If no slash is found, the argument is returned unaltered.

The regular expression ([\w\.[:blank:]\[\]]+)\/([\w\.[:blank:]\[\]]+) is essentially two identical capture groups separated by a forward slash. The symbols used are as follows:

  • (…) - defines a capture group inside the parentheses.
  • \w - matches any word character, A through Z, 0 through 9, and the underscore, case insensitive.
  • \. - matches the period punctuation symbol.
  • [:blank:] - matches the space or the tab character.
  • \[ - matches the left square bracket.
  • \] - matches the right square bracket.
  • […]+ - matches one or more of any characters in the bracketed list.

The regex find/replace is performed by the regex parser function:

{{#rreplace:{{{1}}}|([\w\.[:blank:]\[\]]+)\/([\w\.[:blank:]\[\]]+)|$1 (as $2)}}

Where

  • $1 - gets replaced with the first capture group.
  • $2 - gets replaced with the second capture group.