πŸ“š General & Other

Anchoring, Alternation, and Testing a Keep Filter

A keep filter is without . Its failure mode is worse than a remove filter's: over-matching in a remove filter leaves you with too little data and you notice, while under-matching in a keep filter…

A keep filter is grep without -v. Its failure mode is worse than a remove filter's: over-matching in a remove filter leaves you with too little data and you notice, while under-matching in a keep filter silently discards rows you needed.

Anchor the pattern

An unanchored /blog/ matches /archive/blog/ and /not-a-blog/post. Anchor with ^ where the position is known β€” ^/blog/ is unambiguous and cannot match mid-path.

Alternation needs grouping

^/blog/|/news/ does not mean what it looks like. Alternation has the lowest precedence, so this reads as (^/blog/) or (/news/) β€” the anchor applies only to the first branch. Write ^(/blog/|/news/) with explicit grouping.

Always diff, never trust

Run the inverse filter as well and inspect what was discarded. The rows you did not expect to lose are where the pattern is wrong, and they only ever surface if you look at them deliberately.

Try it: Keep Lines Matching Regex on SeoWolf's Notepad.