---
title: Regex patterns in Grafana datasource
slug: regex-patterns-in-grafana-datasource
createdAt: 2025-09-09T09:49:45.148Z
---

## Introduction

With Regex patterns, you can efficiently retrieve data across multiple measurements simultaneously, enhancing the flexibility and ease of data retrieval within Grafana.

## Example Regex patterns

[regex101](https://regex101.com/r/GgKuCe/1) can be used for trying out Regex patterns.

**Note**

In the Factry Historian datasource we need to wrap the regex pattern with `/`, such as `/<regex_expression>/`. Moreover, if the expression does not contain `^` or `$`, we need to put `.*` in the beginning and/or at the end of the pattern for the pattern to work.

- **/.\*motor\_speed/** : Will return data points of measurements where the measurement name contains “**motor\_speed**” in its name.
- **/^motor\_speed/** : Will return data points of measurements where the measurement name begins with “**motor\_speed**”.
- **/motor\_speed$/** : Will return data points of measurements where the measurement name ends with “**motor\_speed**”.
- **/^first\_.\*\_motor\_speed$/** : Will return data points of measurements where the measurement name starts with “**first\_**” and ends with “**\_motor\_speed**”. `.*` is used for matching anything between the start and the end of the measurement name.
  - **Example:** Captured measurement names can be:
    - first\_01\_a\_motor\_speed
    - first\_02\_b\_motor\_speed
    - first\_03\_c\_motor\_speed
- **/^sensor\_\d+\_temperature$/** : Will return data points of measurements where the measurement name starts with “**sensor\_**” followed by one or more numbers and ends with “**\_temperature**”.
  - **Example:** Captured measurement names can be:
    - sensor\_1\_temperature
    - sensor\_25\_temperature
    - sensor\_100\_temperature
- **/.\*device\_\w+\_status$/** : Will return data points of measurements where “**device\_**” is found, followed by word characters and ends with “**\_status**”.
  - **Example:** Captured measurement names can be:
    - device\_sensorA\_status
    - device\_controller\_status
    - device\_thermometer\_status

