# Howto extract a substring from string type query

**URL:** <https://community.grafana.com/t/howto-extract-a-substring-from-string-type-query/58240>\
**Category:** Time Series Panel\
**Created:** [December 28, 2021, 1:47pm UTC](https://community.grafana.com/t/howto-extract-a-substring-from-string-type-query/58240 "2021-12-28T13:47:58Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![wfjm](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/wfjm/32/20468_2.png) [@wfjm](https://community.grafana.com/u/wfjm)\
**Post date:** [December 28, 2021, 1:47pm UTC](https://community.grafana.com/t/howto-extract-a-substring-from-string-type-query/58240/1 "2021-12-28T13:47:59Z")

</div>

I’m using InfluxDB and Grafana 8.3.  
I’ve also log data in InfluxDB, therefore fields of type `string`.  
I’d like to extract a part of the string from the returned query data and display this in a table.  
The field data is like a key=value list, and I need the chars between a prefix and a delimiter.  
Best would be a regular expression, like `/tag=(.*?),/`.  
Is there any mechanism in Grafana to do this ?

---

<div class="post-metadata">

**Author:** ![anon70503803](https://avatars.discourse-cdn.com/v4/letter/a/8797f3/32.png) [@anon70503803](https://community.grafana.com/u/anon70503803)\
**Post date:** [January 5, 2022, 2:58am UTC](https://community.grafana.com/t/howto-extract-a-substring-from-string-type-query/58240/2 "2022-01-05T02:58:30Z")

</div>

can you please follow [these steps](https://cln.sh/PTgRFb) to share your raw unformatted data? That way, the community can try and mock up your problem 👍

> **[show-inspect-data](https://cln.sh/PTgRFb)**
>
> GIF uploaded to CleanShot Cloud

---

<div class="post-metadata">

**Author:** ![wfjm](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/wfjm/32/20468_2.png) [@wfjm](https://community.grafana.com/u/wfjm)\
**Post date:** [January 5, 2022, 11:32am UTC](https://community.grafana.com/t/howto-extract-a-substring-from-string-type-query/58240/3 "2022-01-05T11:32:53Z")

</div>

The data comes from log messages of the form

```nohighlight
some_text: key1=val1, key2=val2, ...

```

So a regular expression like `/key1=([^,]*)/` would for example extract `val1`.

---

<div class="post-metadata">

**Author:** ![wfjm](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/wfjm/32/20468_2.png) [@wfjm](https://community.grafana.com/u/wfjm)\
**Post date:** [January 11, 2022, 2:30pm UTC](https://community.grafana.com/t/howto-extract-a-substring-from-string-type-query/58240/4 "2022-01-11T14:30:22Z")

</div>

For the extraction of variables there is a mechanism to parse and pick, see

> **[Filter variables with regex](https://grafana.com/docs/grafana/latest/variables/filter-variables-with-regex/#filter-and-modify-using-named-text-and-value-capture-groups)**
>
> Filter variables with regex Using the Regex Query option, you filter the list of options returned by the variable query or modify the options returned. …

But it is, as far as I understand, specific for setting up variables.  
What I’m looking for is a mechanism which returns sub-strings which can be visualized with a `table` panel.

---

<div class="post-metadata">

**Author:** ![migb](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@migb](https://community.grafana.com/u/migb)\
**Post date:** [September 5, 2022, 10:38pm UTC](https://community.grafana.com/t/howto-extract-a-substring-from-string-type-query/58240/5 "2022-09-05T22:38:31Z")

</div>

hi, did you get what you were looking for ? I beleive I have a similar problem, but I have almost out of ideas, probably grafana still not cover what I need.

---

<div class="post-metadata">

**Author:** ![yosiasz](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/yosiasz/32/45847_2.png) [@yosiasz](https://community.grafana.com/u/yosiasz)\
**Post date:** [September 6, 2022, 12:51am UTC](https://community.grafana.com/t/howto-extract-a-substring-from-string-type-query/58240/6 "2022-09-06T00:51:57Z")

</div>

Welcome

Please provide sample data as follows

```auto
_time,_value,_measurement,_field
2022-07-12 10:00:18.240,96.27,mqtt_consumer,Kettle
2022-07-12 11:00:18.240,50.54,mqtt_consumer,Kettle
2022-07-12 12:00:18.240,99.59,mqtt_consumer,Kettle
2022-07-12 13:00:18.240,92.83,mqtt_consumer,Kettle
2022-07-12 14:00:18.240,76.01,mqtt_consumer,Kettle
2022-07-12 15:00:18.240,28.23,mqtt_consumer,Kettle
2022-07-12 16:00:18.240,37.46,mqtt_consumer,Kettle

```

---

<div class="post-metadata">

**Author:** ![migb](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@migb](https://community.grafana.com/u/migb)\
**Post date:** [September 6, 2022, 1:01am UTC](https://community.grafana.com/t/howto-extract-a-substring-from-string-type-query/58240/7 "2022-09-06T01:01:19Z")

</div>

Hi yosiasz, I get to separate the data but now I need to move the obtain values to fields, this way I can make a join transformationI cant find any transformation to get the result values and place it as field

---

<div class="post-metadata">

**Author:** ![yosiasz](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/yosiasz/32/45847_2.png) [@yosiasz](https://community.grafana.com/u/yosiasz)\
**Post date:** [September 6, 2022, 1:03am UTC](https://community.grafana.com/t/howto-extract-a-substring-from-string-type-query/58240/8 "2022-09-06T01:03:28Z")

</div>

hey @migb still waiting for you to provide sample data. Help us help you by providing that data. Is there any reason you cannot? We cant remotely read your data.

---

<div class="post-metadata">

**Author:** ![migb](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@migb](https://community.grafana.com/u/migb)\
**Post date:** [September 6, 2022, 1:06am UTC](https://community.grafana.com/t/howto-extract-a-substring-from-string-type-query/58240/9 "2022-09-06T01:06:29Z")

</div>

not at all, is just that I found another way to get the data to no extract the strings

---

<div class="post-metadata">

**Author:** ![yosiasz](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/yosiasz/32/45847_2.png) [@yosiasz](https://community.grafana.com/u/yosiasz)\
**Post date:** [September 6, 2022, 1:07am UTC](https://community.grafana.com/t/howto-extract-a-substring-from-string-type-query/58240/10 "2022-09-06T01:07:42Z")

</div>

not sure I understand what you are saying but it seems you have been able to resolve your issue.

---

<div class="post-metadata">

**Author:** ![migb](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@migb](https://community.grafana.com/u/migb)\
**Post date:** [September 6, 2022, 1:08am UTC](https://community.grafana.com/t/howto-extract-a-substring-from-string-type-query/58240/11 "2022-09-06T01:08:49Z")

</div>

right, but now I have another one (different topic)

---

<div class="post-metadata">

**Author:** ![smrithishekhar](https://avatars.discourse-cdn.com/v4/letter/s/5daacb/32.png) [@smrithishekhar](https://community.grafana.com/u/smrithishekhar)\
**Post date:** [March 23, 2023, 7:02pm UTC](https://community.grafana.com/t/howto-extract-a-substring-from-string-type-query/58240/12 "2023-03-23T19:02:02Z")

</div>

Hello, I am facing similar problem now, can you tell me how you resolved it?I am using splunk datasource plugin with grafana.i want to get a subsstring from query results into a table
