# Proper RegEx with Mutate\>GSub

**URL:** <https://discuss.elastic.co/t/proper-regex-with-mutate-gsub/229679>\
**Category:** Logstash\
**Created:** [April 24, 2020, 3:11pm UTC](https://discuss.elastic.co/t/proper-regex-with-mutate-gsub/229679 "2020-04-24T15:11:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wwalker](https://avatars.discourse-cdn.com/v4/letter/w/43a26b/32.png) [@wwalker](https://discuss.elastic.co/u/wwalker)\
**Post date:** [April 24, 2020, 3:11pm UTC](https://discuss.elastic.co/t/proper-regex-with-mutate-gsub/229679/1 "2020-04-24T15:11:58Z")

</div>

Pulling what's left of my hair out trying to get this field to properly display. I have log data coming in from a firewall in `key=value` format. I'm using kv to parse all the fields out and I'm left with a field called `[user][name]`. I'm trying to remove the domain so I get just the user, but I can't seem to find the magic sauce that works.

In Kibana, under table view, the `message` field shows `user=domain\\it4all` and in JSON view it shows `user=\"domain\\\\it4all\"`. I've tried about a dozen different expressions but none of them are working. I thought to list out what i tried but I can't fully remember and I don't want to list something that does work and I thought I tried but didnt. Currently, the following is in my pipeline and not working:

```auto
mutate {
      gsub => [
      "[user][name]", "^\w+'\\'", ""
      ]
    }

```

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [April 24, 2020, 5:25pm UTC](https://discuss.elastic.co/t/proper-regex-with-mutate-gsub/229679/2 "2020-04-24T17:25:30Z")

</div>

Having a backslash at the end of a string requires a trick. Use a character group that just includes backslash...

```
mutate { gsub => ["[user][name]", "\w+[\\]{2}", "" ] }
```

---

<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:** [May 22, 2020, 5:25pm UTC](https://discuss.elastic.co/t/proper-regex-with-mutate-gsub/229679/3 "2020-05-22T17:25:41Z")

</div>

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