scalpel@labs: ~/glossary/regex-link-filter.mdx5 sections

Regex Link Filtering

A regex link filter matches links against a regular expression rather than plain text. One pattern selects every PDF, every link under a path, or every URL with a tracking parameter in a single pass.

extension: Scalpel Linksupdated: 2026-08-14read_time: 2 min
less regex-link-filter.mdx

Why it matters

Substring filtering is clumsy for patterns. You can't express "ends with .pdf" or "starts with https" using substring search alone. A regex can. And it scales: one pattern does the work of dozens of substring searches.

If you need to audit PDFs on a large site, a single \.pdf$ regex saves you building a list of manual filters. The time saved on big audits is substantial.

How it works

Regex mode reads your filter as a regular expression instead of a substring. When you enter a pattern, Scalpel Links compiles it and tests every link URL against it. If the URL matches, the link stays; if it doesn't, it's filtered out.

Common patterns:

  • \.pdf$ grabs all PDFs (ends with .pdf).
  • ^https:// means secure links only (starts with https).
  • utm_[a-z]+= catches tracking parameters (utm_source=, utm_medium=, etc.).
  • /blog/\d{4}/ finds blog posts tagged by year (e.g. /blog/2024/).
  • ^https://example\.com keeps only links to example.com.

Case-insensitivity is the sensible default. URLs are case-sensitive by spec, but in practice domains are not. The filter treats youtube.com and YouTube.com as the same site, which is what you want.

What does not matter

Regex patterns have a learning curve, and if you get one wrong, it won't freeze the UI. An unclosed bracket, a malformed range, or too-ambitious backtracking just triggers an error message. Filter with substring until you fix the pattern. Bad regexes don't break the extension.

Also, very complex patterns that take too long to evaluate (catastrophic backtracking) are caught and rejected before they bog down the tab. This keeps the UI responsive even if you paste in an ambitious pattern by accident.

Code example

// Test a few URLs against regex patterns

const urls = [
  'https://example.com/page.pdf',
  'https://example.com/page.html',
  'https://example.com/blog/2024/article',
  'https://example.com/blog/2023/article',
  'https://example.com/?utm_source=google'
];

// Pattern: all PDFs
const pdfPattern = /\.pdf$/;
urls.filter(url => pdfPattern.test(url));
// => ['https://example.com/page.pdf']

// Pattern: secure links only
const httpsPattern = /^https:\/\//;
urls.filter(url => httpsPattern.test(url));
// => all of them (all are https)

// Pattern: blog posts from 2024
const blog2024Pattern = /\/blog\/2024\//;
urls.filter(url => blog2024Pattern.test(url));
// => ['https://example.com/blog/2024/article']

// Pattern: URLs with tracking parameters
const trackerPattern = /utm_[a-z]+=|fbclid=|gclid=/i;
urls.filter(url => trackerPattern.test(url));
// => ['https://example.com/?utm_source=google']

In Scalpel Links, click the "Regex" radio button next to the filter input. Type your pattern. If it's valid, links matching it stay in the list. If it's malformed, you get an error hint and it falls back to substring matching so you don't lose work. Toggle back to plain-text mode whenever you want.

Sources