# Escaping a single backslash in the "replace" part of a regex\_replace

**URL:** <https://forum.ansible.com/t/escaping-a-single-backslash-in-the-replace-part-of-a-regex-replace/23910>\
**Category:** Ansible Project\
**Created:** [March 8, 2017, 11:40am UTC](https://forum.ansible.com/t/escaping-a-single-backslash-in-the-replace-part-of-a-regex-replace/23910 "2017-03-08T11:40:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![akuma\_d](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@akuma\_d](https://forum.ansible.com/u/akuma_d)\
**Post date:** [March 8, 2017, 11:40am UTC](https://forum.ansible.com/t/escaping-a-single-backslash-in-the-replace-part-of-a-regex-replace/23910/1 "2017-03-08T11:40:27Z")

</div>

Hi,  
I need to replace a dot in a string with a “!”. I am using “regex\_replace” but am unable to get the regex to print a single backslash.

I have tried escaping it using double-backslash but that gives me 2 backslashes in the output. Interestingly escaping using 4 backslashes also gives 2 backslashes in the output - so could this be a bug?

Ansible version is 2.2.1.0

`

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [March 9, 2017, 7:24pm UTC](https://forum.ansible.com/t/escaping-a-single-backslash-in-the-replace-part-of-a-regex-replace/23910/2 "2017-03-09T19:24:59Z")

</div>

Your regex is fine, and there is really only one backslash in the output.  
It's the escaping of debug that is fooling you.  
Try adding this task and check the content:

&nbsp;&nbsp;&nbsp;&nbsp;- copy:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: /tmp/test  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;content: "{{ ini }}"

Dick
