This should work:
s/\)\}([a-z])/)};\1/g
In essence, we literally match a close parenthesis followed by a close brace. We then match a letter between a
and z
, but the parentheses around the [a-z]
make that a capture group that we can reference. We can then (and only then) use \1
in the replacement. Without a capture group, it doesn't know what \1
refers to. With one, it does.
Using it with sed
:
% echo 'hello)}world' | sed -Ee 's/\)\}([a-z])/)};\1/g'
hello)};world