# win\_lineinfile backrefs not working

**URL:** <https://forum.ansible.com/t/win-lineinfile-backrefs-not-working/21079>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [April 6, 2016, 4:25pm UTC](https://forum.ansible.com/t/win-lineinfile-backrefs-not-working/21079 "2016-04-06T16:25:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dr1](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@dr1](https://forum.ansible.com/u/dr1)\
**Post date:** [April 6, 2016, 4:25pm UTC](https://forum.ansible.com/t/win-lineinfile-backrefs-not-working/21079/1 "2016-04-06T16:25:42Z")

</div>

Hello great people of ansible persuasion,

I’m trying to do some **win\_lineinfile** with **backrefs.**

Being a core module, it could be I’m doing it wrong, so here it goes - let me know if you have any clue:

`win_lineinfile: dest: c:\Windows\System32\inetsrv\config\applicationHost.config regexp: '^(.*)<urlCompression \/>$' line: '\1<urlCompression doStaticCompression="true" doDynamicCompression="true" />' state: present backrefs: yes backup: yes`

It’s runninng against this

`<urlCompression />`

and after execution I end up with this

`\1<urlCompression doStaticCompression="true" doDynamicCompression="true" />`

it does the job, but i get the \1 instead of the group of spaces. Am I missing anything?

![](http://stylelabs.com/img/stylelabs-logo.png)

Brussels · New York · [stylelabs.com](http://marketingcontenthub.com/)

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [April 6, 2016, 7:35pm UTC](https://forum.ansible.com/t/win-lineinfile-backrefs-not-working/21079/2 "2016-04-06T19:35:39Z")

</div>

Not used this module myself but I think perhaps you need to use $1 instead of \1

Have a look at the integration tests for this module here:

[https://github.com/ansible/ansible/blob/devel/test/integration/roles/test\_win\_lineinfile/tasks/main.yml](https://github.com/ansible/ansible/blob/devel/test/integration/roles/test_win_lineinfile/tasks/main.yml)

There’s a task that looks like this  
`

- name: replace a line with backrefs included in the line  
win\_lineinfile: dest={{win\_output\_dir}}/test.txt state=present line=“New $1 created with the backref” backrefs=yes regexp=“^This is (line 4)$”  
`

hence suggestion to try using $1

HTH

Jon

---

<div class="post-metadata">

**Author:** ![dr1](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@dr1](https://forum.ansible.com/u/dr1)\
**Post date:** [April 8, 2016, 1:01pm UTC](https://forum.ansible.com/t/win-lineinfile-backrefs-not-working/21079/3 "2016-04-08T13:01:53Z")

</div>

Yap, that works, it’s .net regexp after all /me silly. Thx for pointing it out

Also, regading this module the idempotence is slightly broken - I’ve opened an [issue](https://github.com/ansible/ansible-modules-core/issues/3381#issuecomment-206840657) (and provided a dirty fix)
