Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String delete in VIM

Tags:

regex

linux

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 be?

like image 852
Prasanth Madhavan Avatar asked Jun 06 '11 12:06

Prasanth Madhavan


2 Answers

You can use:

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

For the whole file, that's:

:%s/^[0-9]*,[0-9]*,//
like image 53
viraptor Avatar answered Sep 30 '22 18:09

viraptor


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.

like image 42
Johnsyweb Avatar answered Sep 30 '22 16:09

Johnsyweb