๐Ÿ“š General & Other

Suffix Matching Is Cheaper Than It Looks

keeps lines ending in . There are two implementation notes worth having.

grep '\.pdf$' keeps lines ending in .pdf. There are two implementation notes worth having.

The invisible carriage return

A file with Windows line endings has \r before every \n, so no line ends with .pdf โ€” it ends with .pdf\r. The filter returns nothing against data you can plainly see contains PDFs. This is the single most common cause of a suffix filter that "does not work". Strip \r first.

Suffix checks do not need regex

Most languages have endsWith, which is a direct comparison against the tail of the string. It is faster than a regex engine, and it cannot be confused by metacharacters in the suffix โ€” no escaping the dot, no accidental wildcard.

Case sensitivity in file extensions

URLs may carry .PDF as readily as .pdf. Filesystems vary in whether they care; your filter should be explicit either way rather than inheriting a default.

Try it: Keep Lines Ending With on SeoWolf's Notepad.