lineinfile able to change all occurrences of pattern?

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