> On Fri, Sep 25, 2009 at 11:59 AM, Andy Wokula <[email protected]> wrote:
>
>> > Jeremy Conlin schrieb:
>>> > > That didn't quite work and  it's my fault for not giving better 
>>> > > examples.
>>> > >  Here are two lines:
>>> > >
>>> > > The genealogies &  & 1:2--17 &  & 3:23--38 &  &  \\
>>> > > Elisabeth's seclusion & Judaea: Bethlehem &  &  & 1:24--25 &  &  \\
>>> > >
>>> > > I want my regular expression to find the first line and not the second
>>> > > because there is non-whitespace between the second and third ampersand.
>>> > >  What I'm trying to do is replace "1:2--17" with "\index{1:2--17}"
>>> > >
>>> > > Is that example more clear?
>>> > >
>>> > > Thanks,
>>> > > Jeremy
>> >
>> > this way?
>> > pattern:
>> >    /^\%([^&]*&\)\{2}\s*[0-9:-]\+
>> >
>> > substitute command (with \zs added in the pattern):
>> >
>> >    :%s/^\%([^&]*&\)\{2}\s*\zs[0-9:-]\+/\\index{&}/
>> >
>> > will not work if "&" somehow occurs escaped as part of an entry.
>
> Yes this works. Thanks!  Now do you mind help me understand what everything
> means, I don't quite understand everything you did?
>
> Jeremy

Regexp patterns are described here:
    :h pattern

The pattern:
    /^\%([^&]*&\)\{2}\s*[0-9:-]\+

Literal chars: &
Special chars
    ^
    \%( ... \)
    [ ... ]
    [^ ... ]
    *
    \{ ... }
    \s
    \+

Find the help topic e.g.
    :h /^
    :h /\%(
etc.


The replacement string: \\index{&}
    :h sub-replace-special

Literal chars: i n d e x { }
Special chars:
    \\
    &

-- 
Andy

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

Reply via email to