Reputation: 1261
The sample for substituting:
hello world (one) hello world (two two) hello world (three three three)
The result I want:
hello world $one# hello world $two two# hello world $three three three#
I've tried to use:
s/(\(\w\\+\s*\))/$\1#/g
but it does not work.
Upvotes: 0
Views: 92
Reputation: 196476
Doing these two simple substitutions is a lot more intuitive and a lot faster than wasting your time trying to come up with a single one:
:s/(/\$/g
:s/)/#/g
Anyway:
:s/(\([^)]\+\))/\$\1#/g
The search part: we are looking for an opening parenthese, followed by one or more characters that are not closing parentheses that we put in a capture group, followed by a closing parenthese.
The replacement part: we replace with a dollar sign, followed by our capture group, followed by an octothorpe.
Upvotes: 2
Reputation: 1261
Thanks very much for everyone. I have woke out it.:s/(\(\(\w*\s*\)*\))/$\1#/g
. The preceding command can give the right result I want.
Upvotes: 0