The |match filter uses a regular expression [1] to display a pattern existing in the tag, or nothing if that pattern is absent.

  • New in : SPIP 1.4

For example:
retrieve the first word from the title:


display "toto" if that phrase appears in the title:


It is possible to pass 3 arguments to this filter:

  1. the "pattern"): e.g. ^to be found$;
  2. the options (or modifiers): e.g. Uims;
  3. the number of surrounding parentheses (by default, all of the pattern).

But is is also permitted to pass only 2 arguments: the pattern and the number of surrounding parentheses (e.g. #BALISE|match{toto_(\d+)$, 1} which will return only the final digit(s) that directly precede the word ’toto_’).

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|match{#GET{ma_regexp}, Uims, 1})]

Caution :
The |match filter will, if it exists, return only the first occurrence encountered (and not an array of all occurrences).

See also: the |replace filter.


[1Please also reference the Wikipedia page: Regular_expression

Author Mark Published : Updated : 22/07/23

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