# lineinfile able to change all occurrences of pattern?

**URL:** <https://forum.ansible.com/t/lineinfile-able-to-change-all-occurrences-of-pattern/22497>\
**Category:** Ansible Project\
**Created:** [September 6, 2016, 4:13pm UTC](https://forum.ansible.com/t/lineinfile-able-to-change-all-occurrences-of-pattern/22497 "2016-09-06T16:13:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryan\_Groten](https://avatars.discourse-cdn.com/v4/letter/r/f9ae1b/32.png) [@Ryan\_Groten](https://forum.ansible.com/u/Ryan_Groten)\
**Post date:** [September 6, 2016, 4:13pm UTC](https://forum.ansible.com/t/lineinfile-able-to-change-all-occurrences-of-pattern/22497/1 "2016-09-06T16:13:29Z")

</div>

If a regexp matches multiple lines in a file, lineinfile will only change the first occurrence. Is there a way to make change them all? I saw someone used another task to count the number of occurrences of a pattern and then loop using with\_sequence in the lineinfile task but I’m wondering if there’s a cleaner way.

Thanks,  
Ryan
