Regular Expressions in VIM

June 16, 2007 by hejian

Find all the lines which dos contains the “abc”:
/^%(%(abc)@<!.)*$

Search the date string such as “2005-07-12″:
/[0-9]{4}-[0-9]{2}-[0-9]{2}
or:
/v[0-9]{4}-[0-9]{2}-[0-9]{2}

Remove the 39th field of a CSV string:
:%s/(([^,]*,){38})[^,]*,/1/

Find all the lines has “aaa”, and find the fourth “,”, then insert a “‘bbb’, ” at there:
:%s/(^[^(]*aaa[^(]*([^,]*,[^,]*,[^,]*,[^,]*,)/1 ‘bbb’,/g
this command will replace:
REPLACE INTO `aaa` VALUES (107, 101, ”, ”, ‘Thomas’, ‘Rykaceski’, ‘249 Bear Creek Road’, ”, ‘16055′, ‘Sarver’, ”, 223, 51);
with
REPLACE INTO `aaa` VALUES (107, 101, ”, ”, ‘bbb’, ‘Thomas’, ‘Rykaceski’, ‘249 Bear Creek Road’, ”, ‘16055′, ‘Sarver’, ”, 223, 51);

Leave a Reply

You must be logged in to post a comment.

Wordpress template made by HeJian