This is actually more of a regex-question, not ansible. Apart from that, all information you are looking for is in the python documentation and ansible documentation.
\\1
will return the first matching group
/?(.*)
has several parts
/?
will match a /
if it is there, or nothing if it isn't. The ?
means "optional".
- Everything in brackets
()
is a matching-group. You can have multiple to get different parts of your match, but here it is only one.
.*
matches any string composed of any character except new-lines of any length, as .
matches any character (except newline) and *
means, 0 or more characters.
Check the documentation linked above, they explain all this in detail.