开发者

Regex in vim while doing replace

开发者 https://www.devze.com 2023-04-12 07:50 出处:网络
I have a text file with many statements like: \"1\", \"23\",..... etc and I want to replace these occurrences with 1, 23,.... 开发者_JAVA技巧etc. That is just removing the quotes. How can I do this in

I have a text file with many statements like: "1", "23",..... etc and I want to replace these occurrences with 1, 23,.... 开发者_JAVA技巧etc. That is just removing the quotes. How can I do this in VIM?


Use :

:%s/"\(\d\+\)"/\1/g

Which means: replace any sequence of digits between double quotes with the sequence of digits itself.

For more reference:

:help :s
:help pattern


You type esc then:

:%s/\"\([0-9]*\)\"/\1/g

This will substitute the pattern: " any digits " by any digits. Note that \1 will replicate what has been matched within these: \( \)


You can do it like this -

:%s/"\(\d\+\)"/\1/c
0

精彩评论

暂无评论...
验证码 换一张
取 消