Friday, June 8, 2012

RE: How to find and replace using negative lookahead

César Valencia wrote:
> 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 would try a negative lookahead, like this:

:%s/K Value=\%(0000\)\@!\zs\d\{4}/1300/g

That finds "K Value=" not followed by "0000" but followed by
four digits. It then changes the four digits to "1300".

Not tested much!

John

--
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: