Reputation: 6003
I have the following text
tset "abc" "123" kk
test "xyz" "345" zz
How to replace the second string inside double quotas? So the result should be
tset "abc" "replaced" kk
test "xyz" "replaced" zz
Upvotes: 0
Views: 98
Reputation: 10613
An Evil mode solution would be to use this command:
:g/".*".*".*"/norm 3f"lct"replaced
Which means:
g/".*".*".*"
- On any line containing the regex (which matches two quoted strings)norm
- In normal mode3f"lct"replaced
- go to the third "
, move one character right, and change the text until the next "
to "replaced"It also takes ranges, so you can use it on a subset of lines if you want to.
Upvotes: 1
Reputation: 4756
I'm assuming you want to do that in an regular emacs buffer.
I'm also assuming you want to have the second string always replaced with the same value.
Then you can use the replace-regexp
command in emacs as follows:
M-x replace-regexp <RET> \(tset "[^"]*"\) "[^"]*" <RET> \1 "replaced" <RET>
<RET>
represents the Enter/Return key on your keyboard.
This command searches for a string that fits an regular expression in your file and replaces it with what ever you want. The first part is set as a group, everything within the parenthesis, that you want to keep. Expressed as \1
in the replacement string.
Upvotes: 0