content/shared/sql-reference/functions/regular-expression.md
The {{< product-name >}} 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:
Returns the number of matches that a regular expression has in a string.
regexp_count(str, regexp[, start, flags])
^ and $ match the beginning and end of a line, respectively.. matches newline (\n).\r\n is used to delimit lines.x* and x*?.{{< expand-wrapper >}}
{{% expand "View regexp_count query example" %}}
The following example uses the {{< influxdb3/home-sample-link >}}.
SELECT DISTINCT
room,
regexp_count(room::STRING, '[Ro]', 1, 'i') AS regexp_count
FROM home
| room | regexp_count |
|---|---|
| Kitchen | 0 |
| Living Room | 3 |
{{% /expand %}} {{< /expand-wrapper >}}
True if a regular expression has at least one match in a string; false otherwise.
regexp_like(str, regexp[, flags])
^ and $ match the beginning and end of a line, respectively.. matches newline (\n).\r\n is used to delimit lines.x* and x*?.{{< expand-wrapper >}}
{{% expand "View regexp_like query example" %}}
The following example uses the {{< influxdb3/home-sample-link >}}.
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 >}}
Returns a list of regular expression matches in a string.
regexp_match(str, regexp, flags)
{{< expand-wrapper >}}
{{% expand "View regexp_match query example" %}}
The following example uses the {{< influxdb3/home-sample-link >}}.
[!Note]
regexp_matchreturns a list Arrow type. Use bracket notation to reference a value in the list. Lists use 1-based indexing.
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 >}}
Replaces substrings in a string that match a regular expression.
regexp_replace(str, regexp, replacement, flags)
{{< expand-wrapper >}}
{{% expand "View regexp_replace query example" %}}
The following example uses the {{< influxdb3/home-sample-link >}}.
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 >}}