rem par str how to remove few strings
I need to remove rem, par, str from the whole line
rem par str how to remove few strings
I need to remove rem, par, str from the whole line
The main point of this rebus is to remove the strings only and leave the words starting and potentially ending by these strings untouched. The solution is starting and ending the regexp by matching an empty string at word boundary \b
. This will keep the words starting and ending by these strings untouched. Add \s?
to match one space after the string if exists. This will match the strings at the end of the line as well.
Use the module replace. For example, given the file
shell> cat /tmp/test.txt
rem par str how to remove few strings
Put the strings you want to remove into a list
remove_strings: [rem, par, str]
Iterate the list
- replace:
path: /tmp/test.txt
regexp: '\b{{ item }}\b\s?'
replace: ''
loop: "{{ remove_strings }}"
gives
shell> cat /tmp/test.txt
how to remove few strings
- hosts: localhost
vars:
remove_strings: [rem, par, str]
tasks:
- replace:
path: /tmp/test.txt
regexp: '\b{{ item }}\b\s?'
replace: ''
loop: "{{ remove_strings }}"