---
title: Regular expressions
description: Use regular expressions to match patterns in your data.
url: https://docs.influxdata.com/influxdb/v2/query-data/influxql/explore-data/regular-expressions/
estimated_tokens: 2191
product: InfluxDB OSS v2
version: v2
publisher: InfluxData
canonical: https://docs.influxdata.com/influxdb/v2/query-data/influxql/explore-data/regular-expressions/
date: '2025-04-02T15:54:32-06:00'
lastmod: '2025-04-02T15:54:32-06:00'
---

This page documents an earlier version of InfluxDB OSS.[InfluxDB 3 Core](/influxdb3/core/) is the latest stable version.

#### API token hashing is enabled by default in InfluxDB OSS 2.9.0

Stronger token security: tokens are stored as hashes on disk, so a
copy of the database file doesn’t expose usable tokens. Existing
tokens are hashed on first startup and the original strings can’t
be recovered afterward — **capture any plaintext tokens you still
need before you upgrade**.

For more information, see [Token hashing](/influxdb/v2/admin/tokens/#token-hashing).

InfluxQL supports using regular expressions when specifying:

* [field keys](/influxdb/v2/reference/glossary/#field-key) and [tag keys](/influxdb/v2/reference/glossary/#tag-key) in the [`SELECT` clause](/influxdb/v2/query-data/influxql/explore-data/select/).
* [measurements](/influxdb/v2/reference/glossary/#measurement) in the [`FROM` clause](/influxdb/v2/query-data/influxql/explore-data/select/#from-clause).
* [tag values](/influxdb/v2/reference/glossary/#tag-value) and string [field values](/influxdb/v2/reference/glossary/#field-value) in the [`WHERE` clause](/influxdb/v2/query-data/influxql/explore-data/where/).
* [tag keys](/influxdb/v2/reference/glossary/#tag-key) in the [`GROUP BY` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/)

Regular expressions in InfluxQL only support string comparisons and can only evaluate [fields](/influxdb/v2/reference/glossary/#field) with string values.

> [!Note]
> **Note:** Regular expression comparisons are more computationally intensive than exact
> string comparisons. Queries with regular expressions are not as performant
> as those without.

* [Syntax](#syntax)
* [Examples](#examples)

## Syntax

```sql
SELECT /<regular_expression_field_key>/ FROM /<regular_expression_measurement>/ WHERE [<tag_key> <operator> /<regular_expression_tag_value>/ | <field_key> <operator> /<regular_expression_field_value>/] GROUP BY /<regular_expression_tag_key>/
```

Regular expressions are surrounded by `/` characters and use the[Go regular expression syntax](http://golang.org/pkg/regexp/syntax/).

## Supported operators

`=~`: matches against`!~`: doesn’t match against

### Examples

[](#use-a-regular-expression-to-specify-field-keys-and-tag-keys-in-the-select-clause)

Use a regular expression to specify field keys and tag keys in the SELECT clause

```sql
SELECT /l/ FROM "h2o_feet" LIMIT 1
```

Output:

Name: h2o\_feet

|        time        |level description|  location   |water\_level|
|--------------------|-----------------|-------------|------------|
|2019-08-17T00:00:00Z|  below 3 feet   |santa\_monica|2.0640000000|

The query selects all field keys and tag keys that include an `l`.
Note that the regular expression in the `SELECT` clause must match at least one
field key in order to return results for a tag key that matches the regular
expression.

Currently, there is no syntax to distinguish between regular expressions for
field keys and regular expressions for tag keys in the `SELECT` clause.
The syntax `/<regular_expression>/::[field | tag]` is not supported.

[](#use-a-regular-expression-to-specify-field-keys-and-tag-keys-in-function-arguments)

Use a regular expression to specify field keys and tag keys in function arguments

```sql
SELECT MAX(/_level/) FROM "h2o_feet" LIMIT 1
```

Output:

Name: h2o\_feet

|        time        |max\_water\_level|
|--------------------|-----------------|
|2019-08-28T07:24:00Z|      9.964      |

This query uses the InfluxQL [`MAX()` selector function](/influxdb/v2/query-data/influxql/functions/selectors/#max)to find the greatest field value out of all field keys that match the regular expression.

[](#use-a-regular-expression-to-specify-measurements-in-the-from-clause)

Use a regular expression to specify measurements in the FROM clause

```sql
SELECT MEAN("degrees") FROM /temperature/
```

Output:

Name: average\_temperature

|        time        |    mean     |
|--------------------|-------------|
|1970-01-01T00:00:00Z|79.9847293223|

Name: h2o\_feet

|        time        |    mean     |
|--------------------|-------------|
|1970-01-01T00:00:00Z|64.9980273540|

This query uses the InfluxQL [MEAN() function](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) to calculate the average `degrees` for every [measurement](/influxdb/v2/reference/glossary/#measurement) in the [NOAA sample data] that contains the word `temperature`.

[](#use-a-regular-expression-to-specify-tag-values-in-the-where-clause)

Use a regular expression to specify tag values in the WHERE clause

```sql
SELECT MEAN(water_level) FROM "h2o_feet" WHERE "location" =~ /[m]/ AND "water_level" > 3
```

Output:

Name: h2o\_feet

|        time        |    mean    |
|--------------------|------------|
|1970-01-01T00:00:00Z|4.4710766395|

This query uses the InfluxQL [MEAN() function](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) to calculate the average `water_level` where the [tag value](/influxdb/v2/reference/glossary/#measurement) of `location` includes an `m` and `water_level` is greater than three.

[](#use-a-regular-expression-to-specify-a-tag-with-no-value-in-the-where-clause)

Use a regular expression to specify a tag with no value in the WHERE clause

```sql
SELECT * FROM "h2o_feet" WHERE "location" !~ /./
>
```

The query selects all data from the `h2o_feet` measurement where the `location`[tag](/influxdb/v2/reference/glossary/#tag) has no value.
Every data [point](/influxdb/v2/reference/glossary/#point) in the [NOAA water sample data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data) has a tag value for `location`.
It’s possible to perform this same query without a regular expression.
See the [Frequently Asked Questions](/influxdb/v2/reference/faq/#how-do-i-query-data-by-a-tag-with-a-null-value)document for more information.

[](#use-a-regular-expression-to-specify-a-tag-with-a-value-in-the-where-clause)

Use a regular expression to specify a tag with a value in the WHERE clause

```sql
SELECT MEAN("water_level") FROM "h2o_feet" WHERE "location" =~ /./
```

Output:

Name: h2o\_feet

|        time        |    mean    |
|--------------------|------------|
|1970-01-01T00:00:00Z|4.4418434585|

This query uses the InfluxQL [MEAN() function](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) to calculate the average `water_level` across all data with a tag value for `location`.

[](#use-a-regular-expression-to-specify-a-field-value-in-the-where-clause)

Use a regular expression to specify a field value in the WHERE clause

```sql
SELECT MEAN("water_level") FROM "h2o_feet" WHERE "location" = 'santa_monica' AND "level description" =~ /between/
```

Output:

Name: h2o\_feet

|        time        |    mean    |
|--------------------|------------|
|1970-01-01T00:00:00Z|4.4713666916|

This query uses the InfluxQL [MEAN() function](/influxdb/v2/query-data/influxql/functions/aggregates/#mean)to calculate the average `water_level` for all data where the field value of `level description` includes the word `between`.

[](#use-a-regular-expression-to-specify-tag-keys-in-the-group-by-clause)

Use a regular expression to specify tag keys in the GROUP BY clause

```sql
SELECT FIRST("index") FROM "h2o_quality" GROUP BY /l/
```

Output:

name: h2o\_quality  
tags: location=coyote\_creek

|        time        |    mean     |
|--------------------|-------------|
|2019-08-17T00:00:00Z|41.0000000000|

name: h2o\_quality  
tags: location=santa\_monica

|        time        |    mean     |
|--------------------|-------------|
|2019-08-17T00:00:00Z|99.0000000000|

This query uses the InfluxQL [FIRST() function](/influxdb/v2/query-data/influxql/functions/selectors/#first)

to select the first value of `index` for every tag that includes the letter `l`in its tag key.
| time | level description | location | water_level |
| --- | --- | --- | --- |
| time | level description | location | water_level |
| 2019-08-17T00:00:00Z | below 3 feet | santa_monica | 2.0640000000 |

| time | max_water_level |
| --- | --- |
| time | max_water_level |
| 2019-08-28T07:24:00Z | 9.964 |

| time | mean |
| --- | --- |
| time | mean |
| 1970-01-01T00:00:00Z | 79.9847293223 |

| time | mean |
| --- | --- |
| time | mean |
| 1970-01-01T00:00:00Z | 64.9980273540 |

| time | mean |
| --- | --- |
| time | mean |
| 1970-01-01T00:00:00Z | 4.4710766395 |

| time | mean |
| --- | --- |
| time | mean |
| 1970-01-01T00:00:00Z | 4.4418434585 |

| time | mean |
| --- | --- |
| time | mean |
| 1970-01-01T00:00:00Z | 4.4713666916 |

| time | mean |
| --- | --- |
| time | mean |
| 2019-08-17T00:00:00Z | 41.0000000000 |

| time | mean |
| --- | --- |
| time | mean |
| 2019-08-17T00:00:00Z | 99.0000000000 |
