[ar] [ast] [bg] [br] [ca] [co] [cpf] [cs] [da] [de] [en] [eo] [es] [eu] [fa] [fon] [fr] [gl] [id] [it] [ja] [lb] [nl] [oc] [pl] [pt] [ro] [ru] [sk] [sv] [tr] [uk] [vi] [zh] Espace de traduction



June 2010 — updated on : February 2011

All the versions of this article:

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

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: [(#TEXTE|replace{nota\d*})].

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})]

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

Show the template of this page Site powered by SPIP | Translation area | Private area