On Thu, 13 Dec 2018 at 17:42, danish09 <
danishsi...@gmail.com> wrote:
>
> amazing. thanks a lot. tried it just now and it did the magic. However, tried to give it a little thought. I am assuming 1 is for the expression with in the first bracket (). But since it is an OR '|', how does it know which word needs to be replaced with what and in which line. I mean could it not be possible that the words are replaced as privkey3.pem in the first line and cert3.pem in the second line., the other way round.
No. The pipe (OR) means it can match cert.cruk.org.something or
privkey.cruk.org.something.
Because of the parentheses around it, it can be used later on in the
replacement, this is called backreferencing.
And because it's the first match, it will normally be referenced in
the replacement string by '\1'.
However, because you need a number directly after that, this would
mean '\13` - which is interpreted as the 13th match and will fail.
We therefore have to use a numbered group to reference it, which is the '\g<1>'.
The second pair of parentheses also has an OR, meaning that the
extension can either be 'key.pem', or just 'crt'.
Your example doesn't require using that in the replacement later on,
so there is no '\2' or anything.
Dick
> To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/0db22ad8-6dae-4442-b033-d77b7ef7abdb%40googlegroups.com.