# regexp is not working in window ansible

**URL:** <https://forum.ansible.com/t/regexp-is-not-working-in-window-ansible/31838>\
**Category:** Ansible Project\
**Created:** [December 17, 2019, 5:06pm UTC](https://forum.ansible.com/t/regexp-is-not-working-in-window-ansible/31838 "2019-12-17T17:06:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Uppara\_venkat](https://avatars.discourse-cdn.com/v4/letter/u/6a8cbe/32.png) [@Uppara\_venkat](https://forum.ansible.com/u/Uppara_venkat)\
**Post date:** [December 17, 2019, 5:06pm UTC](https://forum.ansible.com/t/regexp-is-not-working-in-window-ansible/31838/1 "2019-12-17T17:06:20Z")

</div>

Hi all,

I would like add a line in particular line, I have written a task as below;

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [December 17, 2019, 9:14pm UTC](https://forum.ansible.com/t/regexp-is-not-working-in-window-ansible/31838/2 "2019-12-17T21:14:57Z")

</div>

> Hi all,
> 
> I would like add a line in particular line, I have written a task as below;
> 
> ---  
> - name: adding script line with package name  
> win\_lineinfile:  
> dest: D:/Software/configurations/uCMDBProbeResponseFile.txt  
> regexp: '^USER\_INSTALL\_DIR= '  
> line: 'USER\_INSTALL\_DIR= F:\\UCMDB\\UCMDBServer'  
> state: present
> 
> But it will add the line in end of the file.  
> " regexp" is not working it's not able to find the line.  
> Could you please help me how to fix this issue.

Hello Venkat,

which line do you have in the file that is supposed to match your regular expression?

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Uppara\_venkat](https://avatars.discourse-cdn.com/v4/letter/u/6a8cbe/32.png) [@Uppara\_venkat](https://forum.ansible.com/u/Uppara_venkat)\
**Post date:** [December 18, 2019, 4:40am UTC](https://forum.ansible.com/t/regexp-is-not-working-in-window-ansible/31838/3 "2019-12-18T04:40:50Z")

</div>

Hi Racke,

Line “USER\_INSTALL\_DIR” is exits in the file, Trying to match the line and add new line in same where it will match.

My issue is it’s not matching new line will add end of file.  
Can you provide me suggestion any other method to fix this issue ?

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [December 18, 2019, 7:54am UTC](https://forum.ansible.com/t/regexp-is-not-working-in-window-ansible/31838/4 "2019-12-18T07:54:29Z")

</div>

> Hi Racke,
> 
> Line "USER\_INSTALL\_DIR" is exits in the file, Trying to match the line and add new line in same where it will match.
> 
> My issue is it's not matching new line will add end of file.  
> Can you provide me suggestion any other method to fix this issue ?

What's the \*exact line\* in your file. You are trying to match on '^USER\_INSTALL\_DIR= ', so the equal sign \*and\* the  
white space are significant. I would remove the white space from your regular expression as I don't think it has to  
be present.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Uppara\_venkat](https://avatars.discourse-cdn.com/v4/letter/u/6a8cbe/32.png) [@Uppara\_venkat](https://forum.ansible.com/u/Uppara_venkat)\
**Post date:** [December 18, 2019, 8:15am UTC](https://forum.ansible.com/t/regexp-is-not-working-in-window-ansible/31838/5 "2019-12-18T08:15:31Z")

</div>

the exact line is “USER\_INSTALL\_DIR= E:\UCMDB\DataFlowProbe” I wanted to change as like"USER\_INSTALL\_DIR= F:\UCMDB\UCMDBServer"  
There is no white space. this is not adding exact line.
