# Mutate gsub \\ not working

**URL:** <https://discuss.elastic.co/t/mutate-gsub-not-working/233455>\
**Category:** Logstash\
**Created:** [May 20, 2020, 5:11am UTC](https://discuss.elastic.co/t/mutate-gsub-not-working/233455 "2020-05-20T05:11:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafael\_Pereira\_Silva](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rafael_pereira_silva/32/68703_2.png) [@Rafael\_Pereira\_Silva](https://discuss.elastic.co/u/Rafael_Pereira_Silva)\
**Post date:** [May 20, 2020, 5:11am UTC](https://discuss.elastic.co/t/mutate-gsub-not-working/233455/1 "2020-05-20T05:11:43Z")

</div>

Hello,

I have a log

```auto
.... \"pattern\":\"^[0-9]{9}$\"},\"typeId\":{\"enum\":[32], \"mysensitivefield\":\"ASDASDLAASDASDASLDASDAZ\" 

```

, I need to replace mysensitivefield information.  
getting like this \*\*\*\*\*\*\*\*\*\* : \*\*\*\*\*\*\*\*\*\*\*\*

I am try

```auto
      mutate {
         gsub => [
           "message", "mysensitivefield([^;]+)\S+", "\1 ****************** \2"
           ]
        }

```

but not working , i believe that i need to replcate \ to "" .

someone had a problem trying to use some filter in \ ?

---

<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:** [May 20, 2020, 4:02pm UTC](https://discuss.elastic.co/t/mutate-gsub-not-working/233455/2 "2020-05-20T16:02:39Z")

</div>

You only have one capture group there. What do you expect \2 to be replaced by?

---

<div class="post-metadata">

**Author:** ![andres-perez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andres-perez/32/136461_2.png) [@andres-perez](https://discuss.elastic.co/u/andres-perez)\
**Post date:** [May 20, 2020, 4:41pm UTC](https://discuss.elastic.co/t/mutate-gsub-not-working/233455/3 "2020-05-20T16:41:11Z")

</div>

That regex doesn't make much sense 🤨

If you want to look for  
`\"mysensitivefield\":\"ASDASDLAASDASDASLDASDAZ\"`  
and transform it to  
`\" ****\":\"**** \"`

one way would be to capture the separators around the value and use them to create a new string with asterisks and the captured separators. There is a also some single/double-quote juggling so I'm not going to claim ownership of this configuration 🙈

```auto
         gsub => ["message", '"mysensitivefield(\\\":\\\").*?(\\\")', '" ****\1**** \2']

```

---

<div class="post-metadata">

**Author:** ![Rafael\_Pereira\_Silva](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rafael_pereira_silva/32/68703_2.png) [@Rafael\_Pereira\_Silva](https://discuss.elastic.co/u/Rafael_Pereira_Silva)\
**Post date:** [May 21, 2020, 3:41am UTC](https://discuss.elastic.co/t/mutate-gsub-not-working/233455/6 "2020-05-21T03:41:45Z")

</div>

Great, Its works.

Thanks

---

<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:** [June 18, 2020, 3:41am UTC](https://discuss.elastic.co/t/mutate-gsub-not-working/233455/7 "2020-06-18T03:41:49Z")

</div>

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