On Mon, Mar 30, 2009 at 5:07 PM, Andreas Bernauer <[email protected]>wrote:

>
> ivan budiselic wrote:
> > Hi,
> >
> > I'll post a simplified version of my problem. Basically, I want to
> > substitute every occurrence of 'a' (the letter a, without the quotes)
> with
> > 'b', but only if 'a' is not inside a string, by which I mean it is not
> > enclosed in double quotes.
> >
> > So, for the line:
> >
> > 1234 a a "a" a
> >
> > I'd like to get:
> >
> > 1234 b b "a" b
> >
> > The question is, is this possible and how.
> >
> > What I've tried is
> > let line = substitute(line, '\([^\"]\{-}\)a', "\\1b", "g")
>
>
> ...because \{-} matches also 0 times; what you wanted is \{-1,}:
>
> let line = substitute('123 a "a" a', '\([^"]\{-1,}\)a', '\1b', 'g')
>

Ok, this worked pretty well, except that it doesn't work for cases when
there's an 'a' at the start of the line (which I might be able to fix), and
the other problem which I wasn't specific enough about, and that is that I'd
like the change to happen to 'a's outside of strings, so for example
"xxxaxxx" shouldn't match. I guess this changes things quite a bit, sorry
for not being clear enough.

Ivan

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

Reply via email to