# Regular Expression on Env Var

**URL:** <https://discuss.elastic.co/t/regular-expression-on-env-var/262295>\
**Category:** Beats\
**Tags:** winlogbeat\
**Created:** [January 26, 2021, 11:59pm UTC](https://discuss.elastic.co/t/regular-expression-on-env-var/262295 "2021-01-26T23:59:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hQWeedEater](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hqweedeater/32/82948_2.png) [@hQWeedEater](https://discuss.elastic.co/u/hQWeedEater)\
**Post date:** [January 26, 2021, 11:59pm UTC](https://discuss.elastic.co/t/regular-expression-on-env-var/262295/1 "2021-01-26T23:59:49Z")

</div>

```auto
processors:
  - add_fields:
    fields: 
        custom_value: "${COMPUTERNAME}"

```

Is it possible to use regex on {COMPUTERNAME} to only return the first X characters or last X characters? I tried adding the above processor then adding a truncate with max of X characters but it didn't work. ^.{5} would technically match on the first 5 characters - is there a way to have WinLogBeat look at the {COMPUTERNAME} env var and run the regex pattern against it and use that value in custom\_value (or any other field name)

---

<div class="post-metadata">

**Author:** ![hQWeedEater](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hqweedeater/32/82948_2.png) [@hQWeedEater](https://discuss.elastic.co/u/hQWeedEater)\
**Post date:** [January 27, 2021, 5:08pm UTC](https://discuss.elastic.co/t/regular-expression-on-env-var/262295/2 "2021-01-27T17:08:17Z")

</div>

Instead of using ${COMPUTERNAME} I was ableto copy host.name field then truncate it using max\_character property to achieve the desired end result.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 24, 2021, 7:08pm UTC](https://discuss.elastic.co/t/regular-expression-on-env-var/262295/3 "2021-02-24T19:08:34Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
