Thursday, June 7, 2012

How to find and replace using negative lookahead

Hi, I want to find all the strings the has "K Value=" not followed by 0000
and replace them for "K Value=1300". This is my original text:

K Value=0010, P Value=1025, Z Value=2000
K Value=2051, P Value=0310, Z Value=5110
K Value=0000, P Value=5025, Z Value=9000

and the result should be:

K Value=1300, P Value=1025, Z Value=2000
K Value=1300, P Value=0310, Z Value=5110
K Value=0000, P Value=5025, Z Value=9000


I can find all the string that matches "K Value" not followed by 0000, using
negative look-ahead:

:/K Value=\(0000\)\@!

But, when I try to do the substitution with

:%s/K Value=\(0000\)\@!/K Value=1300/gc

I get this

K Value=13000010, P Value=1025, Z Value=2000
K Value=13002051, P Value=0310, Z Value=5110
K Value=0000, P Value=5025, Z Value=900


Please, ¿can you tell me how to do the substitution that I want?

Thanks,

César V.

--
View this message in context: http://vim.1045645.n5.nabble.com/How-to-find-and-replace-using-negative-lookahead-tp5708861.html
Sent from the Vim - General mailing list archive at Nabble.com.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: