I have to extract paths from a list of strings excluding the softlink maps.
Example list:
list1:
- 'lrwxrwxrwx 1 usr grp 18 Nov 21 19:53 /path/dummy_link -> /some/file'
- '-rw-r--r-- 1 usr grp 0 Nov 21 17:50 /path/file1.txt'
- 'drwxr-xr-x 1 usr grp 4096 Nov 21 17:51 /path/dir1'
I am trying with map and regex_replace as below:
- debug:
msg: "{{ list1 | map('regex_replace',regxp,bckref) | list }}"
vars:
regxp: '^.+(/path/.+)(.*?)$'
bckref: '\1'
and the result I am getting is:
"msg": [
"/path/dummy_link -> /some/file",
"/path/file1.txt",
"/path/dir1"
]
The expected output is:
"msg": [
"/path/dummy_link",
"/path/file1.txt",
"/path/dir1"
]
What could be the regex to get rid of the substring -> /some/file which will not be present in all the lines?