regex

Description

Coerce a string literal to a regular expression. The input regular expression must be a string literal, it cannot be a computed value such as a column value.

The most important use case for this function is where string inputs are available, but regular expression values are not, such as in dashboard parameters.

Return type

regex

Domain

This is a scalar function (calculates a single output value for a single input row.)

Categories

Usage

regex(string, [ flags ])

Argument

Type

Optional

Repeatable

Restrictions

string

string

no

no

none

flags

string

yes

no

constant

Examples

filter match_regex(log, regex($errorExpr))

Given the parameter $errorExpr, turn that into a regular expression and match the column log against it. Syntax errors in the regular expression will be reported at compile time.

The input string should not contain any surrounding slashes; doing so would match against values that contain slash characters.

filter match_regex(log, regex("[0-9]+"))

This matches where a sequence of one or more digits is present in the log string. This is equivalent to the following:

filter match_regex(log, /[0-9]+/)