21851Re: [Clip] Remove all lines not containing something
- Jun 30, 2011--- In firstname.lastname@example.org, "diodeom" <diomir@...> wrote:
>Thanks, diodeom! We have often been asked to explain such patterns to members who are less acquainted with RegEx. So let me append...
> 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
^ = 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" ;-)
- << Previous post in topic Next post in topic >>