# Use Regex in Dynatrace DQL Queries for Advanced Filtering

**URL:** <https://community.dynatrace.com/t/use-regex-in-dynatrace-dql-queries-for-advanced-filtering/45582>\
**Category:** DQL\
**Tags:** regex, dql\
**Created:** [May 14, 2024, 8:59pm UTC](https://community.dynatrace.com/t/use-regex-in-dynatrace-dql-queries-for-advanced-filtering/45582 "2024-05-14T20:59:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ppaulogustavoem](https://avatars.discourse-cdn.com/v4/letter/p/ccd318/32.png) [@ppaulogustavoem](https://community.dynatrace.com/u/ppaulogustavoem)\
**Post date:** [May 14, 2024, 8:59pm UTC](https://community.dynatrace.com/t/use-regex-in-dynatrace-dql-queries-for-advanced-filtering/45582/1 "2024-05-14T20:59:46Z")

</div>

_Summary:&nbsp;Dynatrace Query Language (DQL) supports regex for advanced filtering and pattern matching. This thread explains syntax, examples, and best practices for using regex in log and metric queries._

Hey folks!

DQL is amazing. It works very well when the logs is in a json format. However, I have a case where the application log is in a complete wild format.

```markup
[critical] consumer.go:117 [!dt dt.trace_id=xxxxx,dt.span_id=xxxx][request_id=xxxx][session_id=][user_id=xxxxxxx]Queue: xxxxxxxx ~~~Message type: createQuoteSummaryTask~~~~~~ Error: ~~~Code: Some Error here~~~ Message: ~~~Stack:~~~ goroutine 315080

```

I know the format is a huge problem, however, I would like to extract a very specific piece of this log using Regex.

Is this possible? I tried to insert a new DPL pattern but I couldn’t understand very well if it would be possible just run a simple regex.

What I want to do is run the following regex along with the parser command: `Error:(.*?)Message:`.

Is this possible?

**What to read next:**

📖&nbsp;&nbsp;[TIP#1: Extracting values from a JSON\_ARRAY using DQL](https://community.dynatrace.com/post/281181#M1698)

📖&nbsp;&nbsp;[How to Parse JSON in Dynatrace DQL Queries?](https://community.dynatrace.com/post/242105)

---

<div class="post-metadata">

**Author:** ![krzysztof\_hoja](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/krzysztof_hoja/32/34625_2.png) [@krzysztof\_hoja](https://community.dynatrace.com/u/krzysztof_hoja)\
**Post date:** [May 20, 2024, 11:40am UTC](https://community.dynatrace.com/t/use-regex-in-dynatrace-dql-queries-for-advanced-filtering/45582/2 "2024-05-20T11:40:33Z")

</div>

You cannot use regex in DPL, but DPL is a pattern matching and parsing language which replaces regex and does the job easier.

Actually such format is not a problem:

```markup
data record(content="[critical] consumer.go:117 [!dt dt.trace_id=xxxxx,dt.span_id=xxxx][request_id=xxxx][session_id=][user_id=xxxxxxx]Queue: xxxxxxxx ~~~Message type: createQuoteSummaryTask~~~~~~ Error: ~~~Code: Some Error here~~~ Message: ~~~Stack:~~~ goroutine 315080")
| parse content, "LD 'Error:' LD:error_message 'Message:'"

```

Of course if you want to take out other fields from such a log line it is possible as well as making the pattern more precise, so it does not catch similar log lines

 ![krzysztof_hoja_0-1716205154747.png](https://global.discourse-cdn.com/dynatrace/original/3X/9/7/97b0c88bfd9934fb0cf7f3b86fd767774b6ce894.png)

Kris
