# Replace special character in stirng to other special character

**URL:** <https://discuss.elastic.co/t/replace-special-character-in-stirng-to-other-special-character/319382>\
**Category:** Logstash\
**Created:** [November 21, 2022, 2:20am UTC](https://discuss.elastic.co/t/replace-special-character-in-stirng-to-other-special-character/319382 "2022-11-21T02:20:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lusynda](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lusynda/32/53557_2.png) [@lusynda](https://discuss.elastic.co/u/lusynda)\
**Post date:** [November 21, 2022, 2:20am UTC](https://discuss.elastic.co/t/replace-special-character-in-stirng-to-other-special-character/319382/1 "2022-11-21T02:20:29Z")

</div>

Hi all

I have a case that i've been trying to do for a very long time.  
I have a string that contain #0D#0A character that i want to replace them with the string \r\n  
I've been trying to use gsub but it doesn't seem to be working at all.

Are there any solutions for what i'm trying to accomplish.

Thanks for your time.

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [November 21, 2022, 2:35am UTC](https://discuss.elastic.co/t/replace-special-character-in-stirng-to-other-special-character/319382/2 "2022-11-21T02:35:09Z")

</div>

Please share a sample of your message and what you have tried with gsub.

---

<div class="post-metadata">

**Author:** ![Rios](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rios/32/95745_2.png) [@Rios](https://discuss.elastic.co/u/Rios)\
**Post date:** [November 21, 2022, 9:54am UTC](https://discuss.elastic.co/t/replace-special-character-in-stirng-to-other-special-character/319382/3 "2022-11-21T09:54:08Z")

</div>

Code:  
`mutate{ gsub => ["message", "#0D#0A", "\r\n"] }`

Data:

```auto
"original" => "something #0D#0Atest#0D#0A..."
"message" => "something \\r\\ntest\\r\\n...",

```

If you want single backslash, use ruby:

`	ruby { code => 'event.set("message", event.get("message").gsub("#0D#0A","\r\n"))' }`

```auto
"message" => "something \r\ntest\r\n..."

```

---

<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:** [December 19, 2022, 9:54am UTC](https://discuss.elastic.co/t/replace-special-character-in-stirng-to-other-special-character/319382/4 "2022-12-19T09:54:33Z")

</div>

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