Loading ...
Sorry, an error occurred while loading the content.

Re: How do I search for pattern A followed by NOT pattern A ?

Expand Messages
  • Tim Chase
    ... For this particular case, you can search for ^ (..... ).* n 1 @! Note that the @! matches the previous atom, so if you re doing something more complex
    Message 1 of 3 , Nov 1, 2011
    • 0 Attachment
      On 11/01/11 06:03, RJA wrote:
      > if I have the buffer below,
      >
      > ppppp 1 2 3 4 5
      > ppppp 1 2 3 4 5
      > ppppv 1 2 3 4 5
      > ppppp 1 2 3 4 5
      >
      > I can type the search
      >
      > /\(ppppp\).*\n\1.*
      >
      > which will match against the first two lines
      >
      > However, I want to pick out lines 2 and 3. How can I do that ?

      For this particular case, you can search for

      ^\(.....\).*\n\1\@!

      Note that the "\@!" matches the previous atom, so if you're doing
      something more complex than the single "\1" atom, you need to
      wrap it in grouping-parens, whether capturing "\(...\)" or
      non-capturing "\%(...\)".

      Also note that the 4th (last) line will be matched because the
      following line doesn't start with the pattern on the current
      line. If you want to mitigate, just change the pattern to

      ^\(.....\).*\n\1\@!.....

      to assert there are 5 things there. Thosse "....." could also be
      written as ".\{5}" for what it's worth.

      For more reading, you can

      :help /\@!

      and the surrounding sections regarding the Perl-ish tokens.

      -tim



      --
      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
    • RJA
      Brilliant, that s exactly what I needed. Thanks very much. - RJA ... -- You received this message from the vim_use maillist. Do not top-post! Type your reply
      Message 2 of 3 , Nov 3, 2011
      • 0 Attachment
        Brilliant, that's exactly what I needed.

        Thanks very much.

        - RJA

        On Nov 1, 11:33 pm, Tim Chase <v...@...> wrote:
        > On 11/01/11 06:03, RJA wrote:
        >
        > > if I have the buffer below,
        >
        > > ppppp 1 2 3 4 5
        > > ppppp 1 2 3 4 5
        > > ppppv 1 2 3 4 5
        > > ppppp 1 2 3 4 5
        >
        > > I can type thesearch
        >
        > > /\(ppppp\).*\n\1.*
        >
        > > which will match against the first two lines
        >
        > > However, I want to pick out lines 2 and 3. How can I do that ?
        >
        > For this particular case, you cansearchfor
        >
        >    ^\(.....\).*\n\1\@!
        >
        > Note that the "\@!" matches the previous atom, so if you're doing
        > something more complex than the single "\1" atom, you need to
        > wrap it in grouping-parens, whether capturing "\(...\)" or
        > non-capturing "\%(...\)".
        >
        > Also note that the 4th (last) line will be matched because the
        > following line doesn't start with thepatternon the current
        > line.  If you want to mitigate, just change thepatternto
        >
        >    ^\(.....\).*\n\1\@!.....
        >
        > to assert there are 5 things there.  Thosse "....." could also be
        > written as ".\{5}" for what it's worth.
        >
        > For more reading, you can
        >
        >    :help /\@!
        >
        > and the surrounding sections regarding the Perl-ish tokens.
        >
        > -tim

        --
        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
      Your message has been successfully submitted and would be delivered to recipients shortly.