# Add a backslash at the end of a string

**URL:** <https://discuss.elastic.co/t/add-a-backslash-at-the-end-of-a-string/239336>\
**Category:** Logstash\
**Created:** [June 30, 2020, 3:37pm UTC](https://discuss.elastic.co/t/add-a-backslash-at-the-end-of-a-string/239336 "2020-06-30T15:37:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Florent\_Fauvin](https://avatars.discourse-cdn.com/v4/letter/f/d2c977/32.png) [@Florent\_Fauvin](https://discuss.elastic.co/u/Florent_Fauvin)\
**Post date:** [June 30, 2020, 3:37pm UTC](https://discuss.elastic.co/t/add-a-backslash-at-the-end-of-a-string/239336/1 "2020-06-30T15:37:36Z")

</div>

Hello,

I want to add a backslash at the end of a field value, but logstash does not allow it:

```
  `mutate { add_field => { "[prefix]" => "%{[domain]}\\"}}`

```

Do you know how I could add a backslash at the end of the string?

Thank you very much,

Florent

---

<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:** [June 30, 2020, 3:43pm UTC](https://discuss.elastic.co/t/add-a-backslash-at-the-end-of-a-string/239336/2 "2020-06-30T15:43:55Z")

</div>

> [@Florent\_Fauvin](#):
>
> Do you know how I could add a backslash at the end of the string?

The way the logstash configuration parser works makes a backslash at the end of a string a problem. If you wanted to remove a backslash from a field there is a trick to do that -- use a character group that contains a single backslash

```
mutate { gsub => ["someField", "[\\]$", "" ] }

```

but you cannot use character groups in a replacement string, so that would not work here. I have not tested it, but it might work if you use a ruby filter, where the parser is looking for a string in single quotes

```
ruby {
    code => '
        event.set("prefix", event.get("domain") + "\\")
    '
}

```

---

<div class="post-metadata">

**Author:** ![Florent\_Fauvin](https://avatars.discourse-cdn.com/v4/letter/f/d2c977/32.png) [@Florent\_Fauvin](https://discuss.elastic.co/u/Florent_Fauvin)\
**Post date:** [June 30, 2020, 4:54pm UTC](https://discuss.elastic.co/t/add-a-backslash-at-the-end-of-a-string/239336/3 "2020-06-30T16:54:02Z")

</div>

It looks like a need so common, that I find it crazy that logstash does not allow it ...

---

<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:** [July 28, 2020, 4:54pm UTC](https://discuss.elastic.co/t/add-a-backslash-at-the-end-of-a-string/239336/4 "2020-07-28T16:54:06Z")

</div>

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