Find & Replace Articles

Try the Find & Replace
Why sed's s/old/new/g Fails With File Paths — Delimiters, Capture Groups, and the GNU vs BSD sed Difference

Why sed's s/old/new/g Fails With File Paths — Delimiters, Capture Groups, and the GNU vs BSD sed Difference

sed's `s/old/new/g` fails when patterns contain forward slashes (like file paths) — but any character can be the delimiter: `s|/usr/local|/usr/share|g` works identically. Here's the complete sed substitution syntax including & for matched content and \1 capture groups, the -i in-place editing difference between GNU sed (Linux) and BSD sed (macOS), and why grep-first-then-sed is the workflow that prevents data loss.

Jun 27, 2026
Regex Works on Characters, Not Structure — Why It Fails on CSV, HTML, and JSON (and What to Use Instead)

Regex Works on Characters, Not Structure — Why It Fails on CSV, HTML, and JSON (and What to Use Instead)

Regex operates on characters, not structure — and applying it to CSV, JSON, or HTML routinely produces wrong results because the same pattern can appear in both structural positions (delimiters, field names) and content positions (inside field values). Here's why commas inside quoted CSV fields confuse naive regex, the HTML-parsing-with-regex problem, when regex on structured text is actually acceptable (log files, single-field formats), and the correct parsers for each format.

Jun 23, 2026
Find & Replace Beyond Basics: Regex Capture Groups, Multi-Cursor Editing, and Safe Project-Wide Replace

Find & Replace Beyond Basics: Regex Capture Groups, Multi-Cursor Editing, and Safe Project-Wide Replace

Find-and-replace with regex capture groups doesn't just substitute text — it can restructure it, swapping argument order or reformatting dates by reusing captured values in the replacement. Here's how capture-group replacements work, when multi-cursor editing is the better tool instead, case-modification syntax for naming-convention conversions, and safe practices for project-wide replace operations.

Jun 17, 2026
Catastrophic Backtracking: Why a Regex That Works Instantly in Testing Can Hang Forever on Real Data

Catastrophic Backtracking: Why a Regex That Works Instantly in Testing Can Hang Forever on Real Data

A find-and-replace that works instantly on a 100-character test string can take minutes (or never finish) on a 10,000-character real document — not because the engine is slow, but because certain regex patterns cause processing time to grow exponentially with input length. Here's how "catastrophic backtracking" works with patterns like (a+)+b, why it's invisible on short test inputs, why it's also a recognized security vulnerability (ReDoS), and how to recognize vulnerable pattern structures.

Jun 14, 2026
Regex for Data Cleaning: Practical Patterns for Messy Real-World Data

Regex for Data Cleaning: Practical Patterns for Messy Real-World Data

Real-world data — phone numbers, dates, emails, log entries, product codes — arrives inconsistently. Here are the regex patterns for the most common data cleaning tasks: phone normalisation, date standardisation, HTML stripping, whitespace cleaning, and log redaction.

Jun 9, 2026