regex

Purpose

The regex() function is used to find text fragments corresponding to a regular expression pattern.

Syntax

regex(regular_expression)

Arguments

The function takes as argument a regular expression enclosed in quotation marks.

The regular expression must correspond to the Perl coding standard (http://perldoc.perl.org/perlre.html).

The function supports the following optional named parameters:

  • scope:=word/sentence/paragraph/text limits the scope of the expression to word/sentence/paragraph/text (by default, scope:=word);

  • ignore_ws:=yes/no allows to ignore/forbid white spaces in a regular expression;

  • casesens:=yes/no switches case sensitivity on/off;

  • wholeword:=yes/no fragment matched by the regular expression is/is not at a word boundary.

If your regex is not matching as expected, try setting scope:=text and ignore_ws:=no
Returned Value

Documents matching the query.

Examples

regex("c.*t") matches "circuit", "conflict", "court" but not "can explain it".

regex("c.*t", scope:=sentence) matches "circuit", "conflict", "court" and "can explain it".

regex("a.*t", wholeword:=no) matches "aircraft", "about", "imaginative" and "statement".

regex("H\\w+", casesens:=yes) matches "He", "His", but not "his", "he".