REGEXP_POSITION()

Documentation

VoltDB Home » Documentation » Using VoltDB

REGEXP_POSITION()

REGEXP_POSITION() — Returns the starting position of a regular expression within a text string.

Synopsis

REGEXP_POSITION( string, pattern [, flag] )

Description

The REGEXP_POSITION() function returns the starting position of the first instance of the specified regular expression within a text string. The position value starts at one (1) for the first position in the string and the functions returns zero (0) if the regular expression is not found.

The first argument to the function is the VARCHAR character string to be searched. The second argument is the regular expression pattern to look for. The third argument is an optional flag that specifies whether the search is case sensitive or not. The flag must be single character VARCHAR with one of the following values:

FlagDescription
cCase-sensitive matching (default)
iCase-insensitive matching

There are several different formats for regular expressions. The REGEXP_POSITION() uses the revised Perl compatible regular expression (PCRE2) syntax, which is described in detail on the PCRE website.

Examples

The following example uses the REGEXP_POSITION() to filter all records where the column description matches a specific pattern. The examples uses the optional flag argument to make the pattern match text regardless of case.

SELECT incident, description FROM securityLog 
    WHERE REGEXP_POSITION(description, 
          'host:\s*10\.186\.[0-9]+\.[0-9]+', 
          'i') > 0 
    ORDER BY incident;