# Ansible lineinfile not working as expected (newbie question)

**URL:** <https://forum.ansible.com/t/ansible-lineinfile-not-working-as-expected-newbie-question/21026>\
**Category:** Ansible Project\
**Created:** [March 30, 2016, 11:55pm UTC](https://forum.ansible.com/t/ansible-lineinfile-not-working-as-expected-newbie-question/21026 "2016-03-30T23:55:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Boyd\_J](https://avatars.discourse-cdn.com/v4/letter/b/c4cdca/32.png) [@Boyd\_J](https://forum.ansible.com/u/Boyd_J)\
**Post date:** [March 30, 2016, 11:55pm UTC](https://forum.ansible.com/t/ansible-lineinfile-not-working-as-expected-newbie-question/21026/1 "2016-03-30T23:55:05Z")

</div>

I’m learning Ansible for a new project, and I’m stuck on what looks like a basic issue.  
Using lineinfile with backrefs and \1 doesn’t work for me.

Simplified playbook to comment out a line starting with “This”:

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [March 31, 2016, 2:08am UTC](https://forum.ansible.com/t/ansible-lineinfile-not-working-as-expected-newbie-question/21026/2 "2016-03-31T02:08:55Z")

</div>

You haven’t actually created a group reference. You have to wrap what you want to reference in () to create a group

So maybe something like:

regexp=‘^(This.\*)’ line=‘#\1’

---

<div class="post-metadata">

**Author:** ![Boyd\_J](https://avatars.discourse-cdn.com/v4/letter/b/c4cdca/32.png) [@Boyd\_J](https://forum.ansible.com/u/Boyd_J)\
**Post date:** [April 1, 2016, 3:55pm UTC](https://forum.ansible.com/t/ansible-lineinfile-not-working-as-expected-newbie-question/21026/3 "2016-04-01T15:55:25Z")

</div>

Aha, thank you, that worked, at least after I changed \1 to \1. Now I understand what group reference and those () I was seeing in examples mean; the \1 and \2 reference those in order.
