# Regex\_replace behavior changes when multi-line string used

**URL:** <https://forum.ansible.com/t/regex-replace-behavior-changes-when-multi-line-string-used/39767>\
**Category:** Get Help\
**Tags:** template\
**Created:** [January 22, 2025, 3:11pm UTC](https://forum.ansible.com/t/regex-replace-behavior-changes-when-multi-line-string-used/39767 "2025-01-22T15:11:13Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![pabigot](https://avatars.discourse-cdn.com/v4/letter/p/7feea3/32.png) [@pabigot](https://forum.ansible.com/u/pabigot)\
**Post date:** [January 22, 2025, 3:27pm UTC](https://forum.ansible.com/t/regex-replace-behavior-changes-when-multi-line-string-used/39767/2 "2025-01-22T15:27:27Z")

</div>

[This related topic](https://forum.ansible.com/t/regex-replace-filter-is-not-working/22730) provided the answer: multiline automatically escapes `\` so this change works:

```
    wai2: >-
      {{ 'ansible' | regex_replace('^a.*i(.*)$', 'a\1') }}

```

---

_[View the full topic](https://forum.ansible.com/t/regex-replace-behavior-changes-when-multi-line-string-used/39767)._
