|match

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

For example:
retrieve the first word from the title: [(#TITRE|match{^\w+?})] ;
display "toto" if that phrase appears in the title: [(#TITRE|match{toto})]

It is possible to pass 3 arguments to this filter:
the "pattern"): e.g. ^to be found$;
the options (or modifiers): e.g. Uims;
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_’).

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

See also: the |replace filter.

Footnotes

[1Please also reference the Wikipedia page: Regular_expression

Author Mark Published : Updated : 26/10/12

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