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

21851Re: [Clip] Remove all lines not containing something

Expand Messages
  • flo.gehrke
    Jun 30, 2011
    • 0 Attachment
      --- In ntb-clips@yahoogroups.com, "diodeom" <diomir@...> wrote:
      >
      > Sorry, Flo -- I quoted the wrong fragment. Here's your pattern I'm referring to, placed in a swap statement:
      >
      > ^!Replace "^.+$(?<!org|net)(\R|\Z)" >> "" WARS

      Thanks, diodeom! We have often been asked to explain such patterns to members who are less acquainted with RegEx. So let me append...

      ^.+$(?<!org|net)(\R|\Z)

      ^ = assertion matching at the start of line
      .+ = one or more characters of any type (except NL)
      $ = end of line

      When arriving at the end of line the RegEx Engine tests...

      (?<!org|net) = Negative Lookbehind Assertion matching a position where you do NOT see 'org' or 'net' when looking behind

      (\R|\Z) = alternation matching a CRNL or the end of string

      In this case, we have genuine negative search criteria in the sense of Don's original question ("Removing lines not containing something"). So to speak, the RegEx is able "to find something that is not there" ;-)

      Regards,
      Flo
    • Show all 30 messages in this topic