# Ansible regex\_replace and replace

**URL:** <https://forum.ansible.com/t/ansible-regex-replace-and-replace/30112>\
**Category:** Ansible Project\
**Created:** [April 15, 2019, 1:00pm UTC](https://forum.ansible.com/t/ansible-regex-replace-and-replace/30112 "2019-04-15T13:00:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryad9200000](https://avatars.discourse-cdn.com/v4/letter/r/f04885/32.png) [@ryad9200000](https://forum.ansible.com/u/ryad9200000)\
**Post date:** [April 15, 2019, 1:00pm UTC](https://forum.ansible.com/t/ansible-regex-replace-and-replace/30112/1 "2019-04-15T13:00:44Z")

</div>

Hi all,

I have two task :

- name: “Utilisation du replace dans un fichier”  
set\_fact:  
mon\_fichier: “{{ lookup(‘file’, ‘/home/ansible/file.txt’) | replace(‘\n’, ’ ') }}”

and

- name: “Utilisation du regex\_replace dans un fichier”  
set\_fact:  
new\_file: “{{ lookup(‘file’, ‘/home/ansible/file.txt’) | regex\_replace(‘mon’,‘le’) }}”

The problem is that this both tasks do the same action.  
So what is a difference between the two module **replace** and **regex\_replace**?

Thanks for your help guy !! 😉

Regards,

---

<div class="post-metadata">

**Author:** ![Emir\_Hayric](https://avatars.discourse-cdn.com/v4/letter/e/58f4c7/32.png) [@Emir\_Hayric](https://forum.ansible.com/u/Emir_Hayric)\
**Post date:** [April 15, 2019, 5:01pm UTC](https://forum.ansible.com/t/ansible-regex-replace-and-replace/30112/2 "2019-04-15T17:01:13Z")

</div>

I am only guessing here but I would assume ‘replace’ just doesn’t use regex syntax to accomplish the same goal.
