# Using variable substitution with replace module and regex

**URL:** <https://forum.ansible.com/t/using-variable-substitution-with-replace-module-and-regex/22180>\
**Category:** Ansible Project\
**Created:** [August 1, 2016, 2:07pm UTC](https://forum.ansible.com/t/using-variable-substitution-with-replace-module-and-regex/22180 "2016-08-01T14:07:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Auto-mate](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@Auto-mate](https://forum.ansible.com/u/Auto-mate)\
**Post date:** [August 1, 2016, 2:07pm UTC](https://forum.ansible.com/t/using-variable-substitution-with-replace-module-and-regex/22180/1 "2016-08-01T14:07:48Z")

</div>

Hi,

I have two register variable in a play and want to replace one with another in a play.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 10, 2017, 3:29am UTC](https://forum.ansible.com/t/using-variable-substitution-with-replace-module-and-regex/22180/2 "2017-02-10T03:29:49Z")

</div>

The way your are doing it seems ok, except you are formating it wrong

either use this form:

- name: Editing the file  
&nbsp;&nbsp;&nbsp;replace: dest=/some/path regexp=^"{{ result.stdout }}."  
replace="{{ result2.stdout }}." backup=yes

or this one:

- name: Editing the file  
&nbsp;&nbsp;&nbsp;replace:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: /some/path  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;regexp: ^"{{ result.stdout }}."  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;replace: "{{ result2.stdout }}."  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;backup: yes
