开发者

String delete in VIM

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜