开发者

String delete in VIM

开发者 https://www.devze.com 2023-03-11 13:28 出处:网络
I have a file that has the general form as number,number,string and i want to delete both the numbers from each line and extract only the string. What would the regexp b开发者_StackOverflow中文版e?

I have a file that has the general form as

number,number,string

and i want to delete both the numbers from each line and extract only the string. What would the regexp b开发者_StackOverflow中文版e?


You can use:

:s/^[0-9]*,[0-9]*,// 

For the whole file, that's:

:%s/^[0-9]*,[0-9]*,//


A good regular expression may be:

/^\(\s*[+-]*[[:digit:]]*\.*[[:digit:]]\+,\s*\)\{2}/

This will match numbers, including an optional sign and an optional decimal point (assuming you use . in your locale) followed by a comma and optional whitespace twice at the beginning of the line.

Usage:

:%s/^\(\s*[+-]*[[:digit:]]*\.*[[:digit:]]\+,\s*\)\{2}//

Add hex digits ([[:xdigit:]]) to taste.

0

精彩评论

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

关注公众号