The |replace filter uses a regular expression [1] to delete all replace all occurrences of a pattern in the tag.

  • New in : SPIP 1.4


Used with a single parameter, a regular expression, the pattern will be deleted.

For example, to delete any occurrences of "notaXX" in the text body:



Whenever a second parameter is passed to the filter, the occurrences of the pattern will be replaced by that value.
For example, to replace all occurrences of "2005" or "2006" in the text body with "2007":

[(#TEXTE|replace{200(5|6), 2007})]


The filter’s arguments may only be simple text strings:
replace all the "au temps" with "autant":

[(#TEXTE|replace{au temps, autant})]


There is even a third parameter that can be passed to the filter. This one corresponds to the options (or modifiers) to be applied to the regexp:

[(#TEXTE|replace{^this$, that, UimsS})]


The default value for this 3rd parameter is UimsS.

Other examples

Replace spaces in a title with a dash:



Replace anything that is not a letter in a title with a dash:



Remove the à(a grave accent) from a title (note the single quotation marks):



Delete the full stop at the end of a title:



Remove punctuation and unnecessary spaces. Place a dash:

[(#TITRE|replace{( |\p{P}|\h)+,-,S})]


It is not possible to declare a class of characters as an argument to the filter: |replace{[0-9]+} will generate a compile error because of the existence of the [ and ] brackets,
It is however still possible to write complex regexps that use character classes if you define them separately beforehand:#SET{my_regexp, ^[[:space:]]*([0-9]+)([.)]|Â?°)[[:space:]]+} [(#DESCRIPTIF|replace{#GET{my_regexp}, __, Uims})]

See also: the |match filter.


[1Please also reference the Wikipedia page: Regular_expression

Author Mark Published : Updated : 22/07/23

Translations : català, English, Español, français, Nederlands