If I'm using a range in a regex, how can I replace with the character that was matched? For example, lets say I want to find all occurrences of a
or b
, and replace them with aa
or bb
. Can I do this in a single regex? For example, something like this:
:%s/[a-b]/\1\1/g
Where \1
means the first matching character? Can I extend this to several characters? For example converting camelCase
to snake_case
. Can I do something like this:
%s/[a-z][A-Z]/\1_\2/g
Where \1
is the first matching character and \2
is the second matching character?