# regex\_replace filter is not working

**URL:** <https://forum.ansible.com/t/regex-replace-filter-is-not-working/22730>\
**Category:** Ansible Project\
**Created:** [October 6, 2016, 1:24pm UTC](https://forum.ansible.com/t/regex-replace-filter-is-not-working/22730 "2016-10-06T13:24:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Venkata\_Jaswanth\_U](https://avatars.discourse-cdn.com/v4/letter/v/67e7ee/32.png) [@Venkata\_Jaswanth\_U](https://forum.ansible.com/u/Venkata_Jaswanth_U)\
**Post date:** [October 6, 2016, 1:24pm UTC](https://forum.ansible.com/t/regex-replace-filter-is-not-working/22730/1 "2016-10-06T13:24:08Z")

</div>

Hi all.  
I am trying to use regex\_replace to capture the host name in a url. This is the code : {{ openerp\_url | regex\_replace(‘^(?:h._//)?(._)(?:(?::|/).\*)$’, ‘\1’) }}. But, when the playbook is run, it is only giving \1 as the output. Checked with the latest ansible dev version as well. No luck. Even, the example given in the documentation {{ ‘ansible’ | regex\_replace(‘^a._i(._)$’, ‘a\1’) }} gives a\1 as output.

Thanks,

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 7, 2016, 10:28pm UTC](https://forum.ansible.com/t/regex-replace-filter-is-not-working/22730/2 "2016-10-07T22:28:43Z")

</div>

I'm using 2.1.2 and can't confirm this behavior.

The playbook i tested

---

<div class="post-metadata">

**Author:** ![Venkata\_Jaswanth\_U](https://avatars.discourse-cdn.com/v4/letter/v/67e7ee/32.png) [@Venkata\_Jaswanth\_U](https://forum.ansible.com/u/Venkata_Jaswanth_U)\
**Post date:** [October 8, 2016, 3:04pm UTC](https://forum.ansible.com/t/regex-replace-filter-is-not-working/22730/3 "2016-10-08T15:04:03Z")

</div>

Found the issue. I was using blockinfile module. The regex\_replace usage in question is sent to the ‘block’ parameter. It was using a multi line string using |. That was automatically escaping the second argument.
