Template:MultiReplace/doc

From MEpedia, a crowd-sourced encyclopedia of ME and CFS science and history

Replaces matches of multiple patterns in a given string with given replacements. For each replacement instance, the pattern matching at the lowest position is chosen. If there are multiple such patterns, then the one specified earliest in the pattern list is chosen.

Usage[edit source]

{{MultiReplace|input|plain=yes (optional)|pattern1|replacement1|pattern2|replacement2...}}

If plain=yes is specified, then the patterns and replacements are treated as plain text, otherwise as Lua Unicode patterns.

Examples[edit source]

Replacing hyphen or slash - with – (&ndash);

  • {{MultiReplace|2019/12/29|plain=yes|pattern1="/"|replacement1="–"}} → 2019/12/29
  • {{MultiReplace|2019-12-29|-|–}} → 2019-12-29

Replacing multiple characters[edit source]

Note named parameters don't work, and plain should be after the first pair only OR a named parameter

  • {{MultiReplace|a bat can fly|a|A|plain=yes|c|C}}
    → A bAt CAn fly

Replace non-consecutive letters a, c, with "ac" or "ca" replaced individually

  • {{MultiReplace|a bat can fly!|a|A|c|C|plain=yes}}
    → A bAt CAn fly!

Regular expressions[edit source]

Plain = no by default. Replace non-consecutive letters a, c, with "ac" or "ca" replaced as a single unit, 1 or more times

  • {{MultiReplace|a bat can fly|plain=no|[ac]+|–}}
    → – b–t –n fly
  • Using an escaped (/) character * to replace multiple characters 0 or more times {{MultiReplace|abcdefghijabc|[aei]/*|–|plain=no}}
    → –bcd–fgh–j–bc
  • Using an escaped (/) character * to replace multiple characters 0 or more times
    {{MultiReplace|That's quite a height!|[aei]/*|–|plain=no}}
    → Th–t's qu–t– – h––ght!
  • NOT (^). Replace non-vowels letters with "ae" or "ei" replaced as a single unit, 1 or more times
    {{MultiReplace|That's quite a height!|plain=no|[^aeiou]+|–}}
    → –a–ui–e–a–ei–

See also[edit source]