I'm tryong to modify a config file with Ansible, but as brackets are considered as regex element, they don't seem to be taken into account.
But if I try to escape them, I have a syntax error… How is it supposed to work?
# does nothing
regexp: "# unicorn['worker_processes'] = 2"
regexp: "# unicorn\['worker_processes'\] = 2"
regexp: '# unicorn\[\'worker_processes\'\] = 2'
The regexes you're talking about are in string literals. That means you should escape the backslashes that come before square brackets like this:
regexp: '# unicorn\\[\'worker_processes\'\\] = 2'
regexp: "# unicorn\\['worker_processes'\\] = 2"