# Ansible win\_lineinfile Assistance

**URL:** <https://forum.ansible.com/t/ansible-win-lineinfile-assistance/37924>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [April 24, 2023, 4:37pm UTC](https://forum.ansible.com/t/ansible-win-lineinfile-assistance/37924 "2023-04-24T16:37:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Huskers79](https://avatars.discourse-cdn.com/v4/letter/h/d78d45/32.png) [@Huskers79](https://forum.ansible.com/u/Huskers79)\
**Post date:** [April 24, 2023, 4:37pm UTC](https://forum.ansible.com/t/ansible-win-lineinfile-assistance/37924/1 "2023-04-24T16:37:19Z")

</div>

Good day all,

Not sure If I’m doing something wrong here or hitting a bug.

Goal is to update the below line.

\<key=“Token” value=“some\_token” /\>

community.windows.win\_lineinfile:  
path: ‘{{ some\_path }}’  
regex: '(.+“Token”.+“).+(” /\>)  
line: ‘$1{{ some\_new\_token }}$2’  
backrefs: true

I end up with:

$1new\_token" /\>

I cannot get $1 to expand when placed directly next to “{{” in line.

line: ‘$1 {{ some\_new\_token }}$2’ # notice space after $1

Results in:

\<key=“Token” value=" new\_token" /\>

Changing my regex and line as below is a workaround, but I’d like to know what I’m missing above.

regex: ‘(.+“Token” value=).+’  
line: ‘$1"{{ some\_new\_token}}" /\>’

Thank you for any insight.

---

<div class="post-metadata">

**Author:** ![atul\_mohan](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@atul\_mohan](https://forum.ansible.com/u/atul_mohan)\
**Post date:** [August 20, 2023, 10:10pm UTC](https://forum.ansible.com/t/ansible-win-lineinfile-assistance/37924/2 "2023-08-20T22:10:01Z")

</div>

- name: Update XML line with new token  
community.windows.win\_lineinfile:  
path: ‘{{ some\_path }}’  
regex: ‘(\<key=“Token” value=“).+(” /\>)’  
line: ‘{{ line | regex\_replace(“(\<key=\“Token\” value=).+( \” /\>)", “\1{{ some\_new\_token }}\2”) }}’  
vars:  
line: ‘{{ lookup(“file”, some\_path) | regex\_replace(“(\r|\n)”, “”) }}’
