docs-v2/content/influxdb/clustered/reference/sql/functions/regular-expression.md

4.6 KiB

title list_title description menu weight influxdb/clustered/tags
SQL regular expression functions Regular expression functions Use regular expression functions to operate on data in SQL queries.
influxdb_clustered
name parent
Regular expression sql-functions
308
regular expressions
sql

The InfluxDB SQL implementation uses the PCRE-like regular expression syntax (excluding some features such as look-around and back-references) and supports the following regular expression functions:

regexp_like

True if a regular expression has at least one match in a string; false otherwise.

regexp_like(str, regexp[, flags])
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.
  • regexp: Regular expression to test against the string expression. Can be a constant, column, or function.
  • flags: Optional regular expression flags that control the behavior of the regular expression. The following flags are supported:
    • i: (insensitive) Ignore case when matching.
    • m: (multi-line) ^ and $ match the beginning and end of a line, respectively.
    • s: (single-line) . matches newline (\n).
    • R: (CRLF) When multi-line mode is enabled, \r\n is used to delimit lines.
    • U: (ungreedy) Swap the meaning of x* and x*?.

{{< expand-wrapper >}} {{% expand "View regexp_replace query example" %}}

The following example uses the sample data set provided in Get started with InfluxDB tutorial.

SELECT DISTINCT
  room,
  regexp_like(room::STRING, 'R', 'i') AS regexp_like
FROM home
room regexp_like
Kitchen false
Living Room true

{{% /expand %}} {{< /expand-wrapper >}}

regexp_match

Returns a list of regular expression matches in a string.

regexp_match(str, regexp, flags)
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.
  • regexp: Regular expression to match against. Can be a constant, column, or function.
  • flags: Regular expression flags that control the behavior of the regular expression. The following flags are supported.
    • i: (insensitive) Ignore case when matching.

{{< expand-wrapper >}} {{% expand "View regexp_replace query example" %}}

The following example uses the sample data set provided in Get started with InfluxDB tutorial.

{{% note %}} regexp_match returns a list Arrow type, which is not supported by InfluxDB. Use bracket notation to reference a value in the list. Lists use 1-based indexing. {{% /note %}}

SELECT DISTINCT
  room,
  regexp_match(room::STRING, '.{3}')[1] AS regexp_match
FROM home
room regexp_match
Kitchen Kit
Living Room Liv

{{% /expand %}} {{< /expand-wrapper >}}

regexp_replace

Replaces substrings in a string that match a regular expression.

regexp_replace(str, regexp, replacement, flags)
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.
  • regexp: Regular expression to match against. Can be a constant, column, or function.
  • replacement: Replacement string expression. Can be a constant, column, or function, and any combination of string operators.
  • flags: Regular expression flags that control the behavior of the regular expression. The following flags are supported.
    • g: (global) Search globally and don't return after the first match.
    • i: (insensitive) Ignore case when matching.

{{< expand-wrapper >}} {{% expand "View regexp_replace query example" %}}

The following example uses the sample data set provided in Get started with InfluxDB tutorial.

SELECT DISTINCT
  room,
  regexp_replace(room::STRING, '\sRoom', '', 'gi') AS regexp_replace
FROM home
room regexp_replace
Kitchen Kitchen
Living Room Living

{{% /expand %}} {{< /expand-wrapper >}}