in reply to Remove all lines, except those starting with pattern
Think of positive/negative look-ahead/look-behind regular expression patterns like this:
Positive Lookahead:e.g. 'this(?=\ that)' # match 'this' when followed by ' that')
Negative Lookahead:e.g. 'this(?!\ that)' # match 'this' when NOT followed by ' that'
Positive Look-behind:e.g. '(?<=this\ )that' # match 'that' when preceded by 'this '
Negative Look-behind:e.g. '(?<!this\ )that' # match 'that' when NOT preceded by 'this '
Both the PRECEDING_PATTERN and the FOLLOWING_PATTERN are matched as the 'look-around' patterns, but neither are captured to a variable, only what is matched as part of your (PATTERN_OF_INTEREST) capture group (i.e. if you use capturing parenthesis).
Edit: replaced 'followed' with 'preceded' as correctly pointed out by AnomalousMonk. Thanks for spotting that :) It was late...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Remove all lines, except those starting with pattern
by AnomalousMonk (Archbishop) on Aug 13, 2018 at 16:53 UTC | |
by perlygapes (Beadle) on Aug 14, 2018 at 14:44 UTC |