Vim: how to undo a regex with a new regex?
Posted
by
Victor Tihomirov
on Stack Overflow
See other posts from Stack Overflow
or by Victor Tihomirov
Published on 2013-11-03T03:10:29Z
Indexed on
2013/11/03
3:53 UTC
Read the original article
Hit count: 757
my I have here a text that has been encrypted in Vi this way:
1,$s/\(.\)\1/&&/g
1,$s/\(.\)\(.\)\2\2\2/\2\2\2\1\2/g
1,$s/\(.\)\(.\)\(.\)\(.\)/\3\1\4\2/g
1,$s/\(...\)\(...\)/\2\1/g
The task is to write a new regex for each regex in order to undo the the changes, so-called decrypting of the text.
I figured out how to undo the last 2 changes:
:1,$s/\(...\)\(...\)/\2\1/g
:1,$s/\(.\)\(.\)\(.\)\(.\)/\2\4\1\3/g
I'd like you to explain me what do the first two regex do. What does \1 or \2\2\2 mean before the forward slash? I assume that after the slash they change place (but wouldn't it be enough to just write \2\1 instead of \2\2\2\1\2(what does it mean?)? I just don't get it). And what does & or && mean?
Thank you
© Stack Overflow or respective owner