1

I am trying to form a regex expression that I would like to use in Dynatrace Request naming rules so it can name the requests that's matching this Regex on a more friendly name and I am having a hard time framing one that suits my needs . The tool only supports "Contains Regex" and "Does not contain Regex" operators which is leading me to match multiple items I dont wish to match .

Example Regex Statement (I use this with "Contains Regex" operator)

/getdata/[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}

Request that I would only like to match :

/getdata/0209133c-6beb-45f4-a9c8-063d86d53609

Other requests that the same regex is matching :

/getdata/0209133c-6beb-45f4-a9c8-063d86d53609/confirm
/getdata/0209133c-6beb-45f4-a9c8-063d86d53609/order/cancel
/getdata/0209133c-6beb-45f4-a9c8-063d86d53609/retry

I understand why its matching it , its basically doing what its asked to do , but I am looking to understand if there is any way to specify what I want using the Contains Regex operator.

2 Answers2

1

The $ end-of-line anchor was designed to help you with exactly this problem. (I will also use the ^ start-of-line anchor as a Best Practice, since it allows us to efficiently skip lines that don't match.)

^/getdata/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$

Almost equivalently we could write a similar regex:

^/getdata/[0-9a-f-]{36}$
J_H
  • 17,926
  • 4
  • 24
  • 44
  • Thank you so much , the $ seem like its doing the trick . This is surely more efficient that the work around I came up with of using a match and an not match :) – Hari Narayanan Apr 15 '23 at 22:24
1

Figured it out in couple of mins after I read my own questions .

So I ended up using -

Matches - /getdata/[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}

Not Matches - /getdata/[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}/

Please someone let me know if there is any other efficient way of handling the same in a single regex statement :)