# regex in Dynatrace to grab last item from /item1/item2/last\_item

**URL:** <https://community.dynatrace.com/t/regex-in-dynatrace-to-grab-last-item-from-item1-item2-last-item/35937>\
**Category:** Open Q&A\
**Tags:** regex\
**Created:** [July 21, 2022, 11:55am UTC](https://community.dynatrace.com/t/regex-in-dynatrace-to-grab-last-item-from-item1-item2-last-item/35937 "2022-07-21T11:55:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![henk\_stobbe](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/henk_stobbe/32/30434_2.png) [@henk\_stobbe](https://community.dynatrace.com/u/henk_stobbe)\
**Post date:** [July 21, 2022, 11:55am UTC](https://community.dynatrace.com/t/regex-in-dynatrace-to-grab-last-item-from-item1-item2-last-item/35937/1 "2022-07-21T11:55:07Z")

</div>

Hello,

Without getting greedy (-; who knows how to solve below,

/item1/item2/last\_item&nbsp; should transform to last\_item

Who can solve this, non greedy (and yes I know it is a lame joke)

KR Henk

---

<div class="post-metadata">

**Author:** ![Julius\_Loman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/julius_loman/32/51_2.png) [@Julius\_Loman](https://community.dynatrace.com/u/Julius_Loman)\
**Post date:** [July 21, 2022, 1:06pm UTC](https://community.dynatrace.com/t/regex-in-dynatrace-to-grab-last-item-from-item1-item2-last-item/35937/2 "2022-07-21T13:06:34Z")

</div>

The following should work, does it?

```markup
/([^/]*+)$

```

---

<div class="post-metadata">

**Author:** ![henk\_stobbe](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/henk_stobbe/32/30434_2.png) [@henk\_stobbe](https://community.dynatrace.com/u/henk_stobbe)\
**Post date:** [July 21, 2022, 2:11pm UTC](https://community.dynatrace.com/t/regex-in-dynatrace-to-grab-last-item-from-item1-item2-last-item/35937/3 "2022-07-21T14:11:58Z")

</div>

Hi Julius,

(you missed an escape so&nbsp; change to ([^\/]\*+)$&nbsp; &nbsp;)

“Dynatrace says to expensive!”&nbsp; but after a lot of tries it seems that the solution is super simple,

(when you see it (-😉

[a-z,A-Z]+$ (or a variation of course)

KR Henk

KR Henk

---

<div class="post-metadata">

**Author:** ![Julius\_Loman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/julius_loman/32/51_2.png) [@Julius\_Loman](https://community.dynatrace.com/u/Julius_Loman)\
**Post date:** [July 21, 2022, 3:32pm UTC](https://community.dynatrace.com/t/regex-in-dynatrace-to-grab-last-item-from-item1-item2-last-item/35937/4 "2022-07-21T15:32:00Z")

</div>

No, my regex ix fine I think. You need to specify the head / as without it it’s expensive. Also it depends on where within Dynatrace you are using it.  
It works for the request naming rules (using the aaa placeholder):

 ![Julius_Loman_0-1658417403400.png](https://global.discourse-cdn.com/dynatrace/original/2X/c/ca11e657b8b152b8e9f0e72ee3f3b735d2d136b5.png)

RUM has different regex limits, so it’s better to ask where you need it exactly.

---

<div class="post-metadata">

**Author:** ![henk\_stobbe](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/henk_stobbe/32/30434_2.png) [@henk\_stobbe](https://community.dynatrace.com/u/henk_stobbe)\
**Post date:** [July 22, 2022, 8:23am UTC](https://community.dynatrace.com/t/regex-in-dynatrace-to-grab-last-item-from-item1-item2-last-item/35937/5 "2022-07-22T08:23:17Z")

</div>

Hello Julius,

Customer was using regex in calculated metric, so you are right yours works perfect.

(except in calculated metric than mine is better (-😉

 ![henk_stobbe_0-1658835498777.png](https://global.discourse-cdn.com/dynatrace/original/1X/73bbb64e96fae5a42524284244724f05dfcf25f0.png)

And yes I know that is very deep (-;

Thank for your reaction!

KR Henk
