# How to use regex with DQL?

**URL:** <https://community.dynatrace.com/t/how-to-use-regex-with-dql/48842>\
**Category:** DQL\
**Tags:** regex, dql\
**Created:** [November 12, 2024, 10:23am UTC](https://community.dynatrace.com/t/how-to-use-regex-with-dql/48842 "2024-11-12T10:23:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jegron](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/jegron/32/12797_2.png) [@jegron](https://community.dynatrace.com/u/jegron)\
**Post date:** [November 12, 2024, 10:23am UTC](https://community.dynatrace.com/t/how-to-use-regex-with-dql/48842/1 "2024-11-12T10:23:06Z")

</div>

Hi,

I’d like to build a complex regex in DQL. I can’t use the same syntax as OneAgent’s masking rule, so I tested the parse command:

```markup
fetch logs
| parse content, "DATA ([:space:]|[:punct:])([12][0-9]{2}[0][1-9][0-9]{2}[0-9]{3}[0-9]{3}[0-9]{2}):myfield1([:space:]|[:punct:])"
| parse content, "DATA ([:space:]|[:punct:])([12][0-9]{2}[1][0-2][0-9]{2}[0-9]{3}[0-9]{3}[0-9]{2}):myfield2([:space:]|[:punct:])"
| parse content, "DATA ([:space:]|[:punct:])([12][0-9]{2}[0][1-9][2][A-B][0-9]{3}[0-9]{3}[0-9]{2}):myfield3([:space:]|[:punct:])"
| parse content, "DATA ([:space:]|[:punct:])([12][0-9]{2}[1][0-2][2][A-B][0-9]{3}[0-9]{3}[0-9]{2}):myfield4([:space:]|[:punct:])"
| fields myfield=coalesce(myfield1, myfield4, myfield3, myfield4), content, log.source, k8s.namespace.name
| filterOut isNull(myfield)

```

or

```markup
fetch logs
| parse content, "DATA ([:space:]|[:punct:])(([12][0-9]{2}[0][1-9][0-9]{2}[0-9]{3}[0-9]{3}[0-9]{2}):myfield|([12][0-9]{2}[1][0-2][0-9]{2}[0-9]{3}[0-9]{3}[0-9]{2}):myfield|([12][0-9]{2}[0][1-9][2][A-B][0-9]{3}[0-9]{3}[0-9]{2}):myfield|([12][0-9]{2}[1][0-2][2][A-B][0-9]{3}[0-9]{3}[0-9]{2}):myfield)([:space:]|[:punct:])"
| fields myfield, content, log.source, k8s.namespace.name
| filterOut isNull(myfield)

```

But this costs “four DQL queries” (for each alternative) and this is not acceptable to the customer&nbsp;because of the high volume …  
What’s the best practice for complex regexes? Is there a roadmap for improving the use of regexes with DQL?&nbsp;Or to harmonize the syntax used in the platform?

Thanks for your help 🙂

---

<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:** [November 13, 2024, 12:51pm UTC](https://community.dynatrace.com/t/how-to-use-regex-with-dql/48842/2 "2024-11-13T12:51:04Z")

</div>

Applying multiple parsing rules on same data does not increase query cost. It only depends in how much data you needs to access.  
Of course heavy parsing parsing will affect query performance, but use of regex will not improve anything here.
