# Regex for Hostname

**URL:** <https://community.dynatrace.com/t/regex-for-hostname/53501>\
**Category:** Open Q&A\
**Tags:** regex, tagging\
**Created:** [September 24, 2025, 8:02pm UTC](https://community.dynatrace.com/t/regex-for-hostname/53501 "2025-09-24T20:02:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bill\_scheuernst](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/bill_scheuernst/32/2211_2.png) [@bill\_scheuernst](https://community.dynatrace.com/u/bill_scheuernst)\
**Post date:** [September 24, 2025, 8:02pm UTC](https://community.dynatrace.com/t/regex-for-hostname/53501/1 "2025-09-24T20:02:23Z")

</div>

I’ve been working on updating our automatic tag rules for a current project and would like to use Regex to capture a device type from a dns name, i.e. [ABCCORE01.TEST.COM](http://ABCCORE01.TEST.COM).&nbsp; The ABC prefix is the location of the device, and&nbsp; **CORE** is the device type.&nbsp; I would like to only use the device type as an optional tag value, such as “Device Capability: \<value\>”.&nbsp; I’m sure this is nothing new.

This worked in regex101, but not in DT…

^[a-zA-Z0-9]{0,3}([a-zA-Z]+?)\d

The location prefix can be ABC or AB1.

---

<div class="post-metadata">

**Author:** ![Mohamed\_Hamdy](https://avatars.discourse-cdn.com/v4/letter/m/7ab992/32.png) [@Mohamed\_Hamdy](https://community.dynatrace.com/u/Mohamed_Hamdy)\
**Post date:** [September 25, 2025, 5:59am UTC](https://community.dynatrace.com/t/regex-for-hostname/53501/2 "2025-09-25T05:59:19Z")

</div>

you can try this one,&nbsp;{Host:DetectedName/^AB[C0-9]([^.]\*+).\*$/$1/}

---

<div class="post-metadata">

**Author:** ![PacoPorro](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/pacoporro/32/36087_2.png) [@PacoPorro](https://community.dynatrace.com/u/PacoPorro)\
**Post date:** [September 25, 2025, 8:00am UTC](https://community.dynatrace.com/t/regex-for-hostname/53501/3 "2025-09-25T08:00:08Z")

</div>

Please check&nbsp;[Regular expressions in Dynatrace — Dynatrace Docs](https://docs.dynatrace.com/docs/shortlink/regex)

From my experience: pick the ungreedy option to test in regex101

 ![PacoPorro_0-1758787049216.png](https://global.discourse-cdn.com/dynatrace/original/2X/2/27d7c12006803f1648be60f4975bc648d004fe27.png)  
&nbsp;  
with ^[A-Za-z0-9]{3}([A-Za-z]+?)\d+\.

 ![PacoPorro_1-1758787191067.png](https://global.discourse-cdn.com/dynatrace/original/2X/0/02810179b20985308ee4d9a97c8efe037dbfbf03.png)
