Wednesday, August 26, 2009

Re: Correcting malformed csv

> Thanks. That took care of most of it. I did have a few of those
> pathological cases, but I'm more than 90% there. I think I understand
> most of the regex, but I'm not familiar with the \%. Looking through
> the help didn't help me understand this particular usage.

It's \%(...\) which is a non-capturing group:

:help /\%(

Assuming the contained quotes always come in pairs, you might be
able to do something like


:%s/\(^\|,\)"\zs\%([^"]\|"[^",]*"\)*\ze"/\=substitute(submatch(0),
'"', '""', 'g')/g


which should handle some of the more pathological conditions. It
does have the limitation that the contained quote can't contain a
comma:

...,"she said, "goodbye, John" and walked away", ...

-tim


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

No comments: