I'm trying 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"
# error
regexp: "# unicorn\['worker_processes'\] = 2"
# error
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'
Even better:
regexp: "# unicorn\\['worker_processes'\\] = 2"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With