# HALP! Changing two backslashes to one!

**URL:** <https://discuss.elastic.co/t/halp-changing-two-backslashes-to-one/201707>\
**Category:** Logstash\
**Created:** [October 1, 2019, 1:12am UTC](https://discuss.elastic.co/t/halp-changing-two-backslashes-to-one/201707 "2019-10-01T01:12:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![joaociocca](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joaociocca/32/15827_2.png) [@joaociocca](https://discuss.elastic.co/u/joaociocca)\
**Post date:** [October 1, 2019, 1:12am UTC](https://discuss.elastic.co/t/halp-changing-two-backslashes-to-one/201707/1 "2019-10-01T01:12:09Z")

</div>

So, I thought this would be trivial, right?

```auto
gsub => ["message","\\\\","\\"]

```

but... nop, it doesn't work. Logstash no like it. There's this field with domain and username that comes out as `domain\\username` from the log message. Everything else is already working nicely, but when I uncomment that specific line...

```auto
Expected one of #, {, ,, ] at line

```

---

<div class="post-metadata">

**Author:** ![joaociocca](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joaociocca/32/15827_2.png) [@joaociocca](https://discuss.elastic.co/u/joaociocca)\
**Post date:** [October 1, 2019, 8:25pm UTC](https://discuss.elastic.co/t/halp-changing-two-backslashes-to-one/201707/2 "2019-10-01T20:25:06Z")

</div>

Never mind, it was just ruby\_debug log escaping a single backslash...

---

<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 1, 2019, 9:29pm UTC](https://discuss.elastic.co/t/halp-changing-two-backslashes-to-one/201707/3 "2019-10-01T21:29:03Z")

</div>

In case you ever do need to do it (or someone's forum search gets a hit on your title) it is hard to get logstash to allow a backslash before the closing quote surrounding a string, so you represent each backslash using one occurrence of the character class that only includes backslash, then use a capture group in the replacement string

```
mutate { gsub => ["someField", "([\\])[\\]", "\1" ] }
```

---

<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:** [October 29, 2019, 9:29pm UTC](https://discuss.elastic.co/t/halp-changing-two-backslashes-to-one/201707/4 "2019-10-29T21:29:08Z")

</div>

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