# Calculated service metrics to capture request name containing regex

**URL:** <https://community.dynatrace.com/t/calculated-service-metrics-to-capture-request-name-containing-regex/38300>\
**Category:** Open Q&A\
**Tags:** regex, dynatrace-managed, services-classic\
**Created:** [February 6, 2023, 8:13pm UTC](https://community.dynatrace.com/t/calculated-service-metrics-to-capture-request-name-containing-regex/38300 "2023-02-06T20:13:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fisher](https://avatars.discourse-cdn.com/v4/letter/f/a8b319/32.png) [@Fisher](https://community.dynatrace.com/u/Fisher)\
**Post date:** [February 6, 2023, 8:13pm UTC](https://community.dynatrace.com/t/calculated-service-metrics-to-capture-request-name-containing-regex/38300/1 "2023-02-06T20:13:44Z")

</div>

Hello, team!

I try to create a calculated service metric. It must capture request like: /projects/{projectId}/files/\*\*

For example: projects/platform\_features/files/help/

When I create a metric, I use the condition “request name contains regex /project\/.\*\/files/.\*[a-zA-Z0-9]” - this condition doesn’t work, because in metric there is “no data”, but I see these requests in MDA.

I tried to use another regex: /project/[a-zA-Z0-9]\*/files/.\*[a-zA-Z0-9] - but Dynatrace show me the message&nbsp;“Greedy or lazy character classes are not allowed, please use a possessive quantifier instead.”

And I tried the third variant:&nbsp;/project/[a-zA-Z0-9]/files/.\*[a-zA-Z0-9] - Dynatrace doesn’t show me an error, but when I try check this regex in [regex101.com](http://regex101.com) - it’s an “invalid expression”.

Could you help me?

---

<div class="post-metadata">

**Author:** ![MichalOlszewski](https://avatars.discourse-cdn.com/v4/letter/m/cab0a1/32.png) [@MichalOlszewski](https://community.dynatrace.com/u/MichalOlszewski)\
**Post date:** [February 7, 2023, 5:31am UTC](https://community.dynatrace.com/t/calculated-service-metrics-to-capture-request-name-containing-regex/38300/2 "2023-02-07T05:31:17Z")

</div>

Hi [@Fisher](https://community.dynatrace.com/user/49132),

2 things with Your regexes -

- 1st You forgetting to escape special char “/” which should always be “\/” - even thou some engines accept unescaped “/” is highly recommended to do so. Every one You posted here have this issue in one or more places
- 2nd don’t use .\*[set] as way out of greedy/lazy/possessive as it won’t work and will cause mess.

I Believe You were looking for:

\/project\/[a-zA-Z0-9]++\/files\/[a-zA-Z0-9]++

 ![MichalOlszewski_0-1675747771543.png](https://global.discourse-cdn.com/dynatrace/original/3X/e/7/e76a428dd13ad0bdf6e0cc7ff25bd7f40e3700e4.png)

Small tip for future with regexes 🙂

- +,\*&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; is greedy - takes as much as possible - You don’t want that (mostly)
- ++, \*+&nbsp; &nbsp; is possessive - takes as much as needed - You usually want that (with rules and filtering)
- +?, \*?&nbsp; &nbsp; &nbsp;is lazy - takes as few as needed - You might want that (with capturing)

---

<div class="post-metadata">

**Author:** ![Fisher](https://avatars.discourse-cdn.com/v4/letter/f/a8b319/32.png) [@Fisher](https://community.dynatrace.com/u/Fisher)\
**Post date:** [February 7, 2023, 9:46am UTC](https://community.dynatrace.com/t/calculated-service-metrics-to-capture-request-name-containing-regex/38300/3 "2023-02-07T09:46:09Z")

</div>

Thank you, Michal.

But it doesn’t work(

I still can’t see data in this calculated metric

---

<div class="post-metadata">

**Author:** ![Romanenkov\_Al3x](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/romanenkov_al3x/32/36257_2.png) [@Romanenkov\_Al3x](https://community.dynatrace.com/u/Romanenkov_Al3x)\
**Post date:** [February 7, 2023, 11:09am UTC](https://community.dynatrace.com/t/calculated-service-metrics-to-capture-request-name-containing-regex/38300/4 "2023-02-07T11:09:45Z")

</div>

Hello from Nightmare…

| \/projects\/(?\>[a-zA-Z0-9-\_]++)\/files\/(?\>[a-zA-Z0-9-\_]++)\/ |
| --- |

Regards,

Romanenkov Alex

---

<div class="post-metadata">

**Author:** ![Fisher](https://avatars.discourse-cdn.com/v4/letter/f/a8b319/32.png) [@Fisher](https://community.dynatrace.com/u/Fisher)\
**Post date:** [February 7, 2023, 12:05pm UTC](https://community.dynatrace.com/t/calculated-service-metrics-to-capture-request-name-containing-regex/38300/5 "2023-02-07T12:05:16Z")

</div>

[@Romanenkov\_Al3x](https://community.dynatrace.com/user/51881)

[@MichalOlszewski](https://community.dynatrace.com/user/51714)

Colleagues,&nbsp; thanks for help!

But trouble was so easy - I missed letter “s” in word project

I’m sorry!

---

<div class="post-metadata">

**Author:** ![Ana.Kuzmenchuk](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@Ana.Kuzmenchuk](https://community.dynatrace.com/u/Ana.Kuzmenchuk)\
**Post date:** [February 7, 2023, 2:04pm UTC](https://community.dynatrace.com/t/calculated-service-metrics-to-capture-request-name-containing-regex/38300/6 "2023-02-07T14:04:09Z")

</div>

Hi&nbsp;[@Fisher](https://community.dynatrace.com/user/49132)&nbsp;thank you for sharing what the solution happened to be! Even though it was a typo, it started a discussion that I think many people will find useful!
