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

Re: Matching a pattern NOT containing another pattern

Expand Messages
  • Hari Krishna Dara
    ... The way I usually manage with -ve part of the patterns is that I first search without that and get the matching lines in a separate window, and further
    Message 1 of 9 , Apr 2, 2006
    • 0 Attachment
      On Fri, 31 Mar 2006 at 7:13am, Dave Roberts wrote:

      > Charles E Campbell Jr wrote:
      > > Dave Roberts wrote:
      > >
      > >> Is it possible to match a pattern only if it does not contain another
      > >> specified pattern anywhere in it?
      > >>
      > >> For example, match a 'foo' followed by a 'bar' as long as there is no
      > >> 'dave' between the foo and bar.
      > >>
      > >> So this foo line matches bar according to dave (no embedded dave)
      > >> but this foo line, according to dave, doesn't match bar. (embedded dave)
      > >>
      > >> It's easy enough to match if the pattern is in a specific place but
      > >> how to match (or not) if the pattern can be anywhere?
      > >>
      > >> Apologies if this is described right in front of me in "pattern.txt"
      > >> - it's getting late...
      > >
      > >
      > > Try LogiPat,
      > > http://vim.sourceforge.net/scripts/script.php?script_id=1290 .
      > > It provides !, & and | (logical not, logical and, logical or)
      > > operators and () for grouping.
      > >
      > > :LP !"foo.*dave.*bar"
      > >
      > > Regards,
      > > Chip Campbell
      > >
      >
      > I've looked at LogiPat before and it's useful but I'm looking at these
      > regular expressions to figure out how to do syntax coloring on a
      > complicated multi-line pattern that can have the same start and end
      > patterns but differ by embedded patterns that mean something different
      > if they themselves have a match or not inside the pattern. I'm getting
      > closer using \@! but am still having trouble in one place.
      >
      > If I can't figure it out I'll post the whole thing eventually to let
      > someone else have a crack at at.
      >
      > Thanks,
      >
      > - Dave

      The way I usually manage with -ve part of the patterns is that I first
      search without that and get the matching lines in a separate window, and
      further narrow them by remove the lines matching the -ve pattern. This
      requires multiple steps, and might not always suit your needs, but it
      usually is simple enough. You can use grep to generate errorlist and
      work on the error-list window, but I prefer to use my greputils plugin
      to redirect the :g/re/p result to a window.

      --
      HTH,
      Hari

      __________________________________________________
      Do You Yahoo!?
      Tired of spam? Yahoo! Mail has the best spam protection around
      http://mail.yahoo.com
    • Charles E Campbell Jr
      ... Well, LogiPat does save its result in the @/ register, but you can also ... HTH, Chip Campbell
      Message 2 of 9 , Apr 3, 2006
      • 0 Attachment
        Dave Roberts wrote:

        > I've looked at LogiPat before and it's useful but I'm looking at these
        > regular expressions to figure out how to do syntax coloring on a
        > complicated multi-line pattern that can have the same start and end
        > patterns but differ by embedded patterns that mean something different
        > if they themselves have a match or not inside the pattern. I'm getting
        > closer using \@! but am still having trouble in one place.
        >
        > If I can't figure it out I'll post the whole thing eventually to let
        > someone else have a crack at at.

        Well, LogiPat does save its result in the @/ register, but you can also
        see what it would produce:

        :echo LogiPat('"abc" & "def")
        :echo LogiPat('! "pattern")

        HTH,
        Chip Campbell
      Your message has been successfully submitted and would be delivered to recipients shortly.