# Can't replace character with Backslash with gsub

**URL:** <https://discuss.elastic.co/t/cant-replace-character-with-backslash-with-gsub/287501>\
**Category:** Logstash\
**Created:** [October 23, 2021, 8:45pm UTC](https://discuss.elastic.co/t/cant-replace-character-with-backslash-with-gsub/287501 "2021-10-23T20:45:42Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [October 23, 2021, 9:07pm UTC](https://discuss.elastic.co/t/cant-replace-character-with-backslash-with-gsub/287501/2 "2021-10-23T21:07:42Z")

</div>

As you have found, you cannot have a backslash as the last character in a quoted string. Using a character group is the normal trick for the pattern. If you use it in the replacement string it is a literal, not a group. So you could do

```
mutate {
    gsub => [
        "PoundedUNC", "#", "\]",
        "PoundedUNC", "]", ""
    ]
}

```

It does not have to be ], you can use any character that will never appear in the UNC.

---

_[View the full topic](https://discuss.elastic.co/t/cant-replace-character-with-backslash-with-gsub/287501)._
