← All articles

October 26, 2026 · 6 min read

Regex Basics for Everyday Spreadsheet and Writing Tasks

Five regular expression patterns non-programmers can memorize once, covering phone numbers, emails, and messy text cleanup.

Regex Basics for Everyday Spreadsheet and Writing Tasks — cover illustration

An editor I worked with needed to pull every hashtag out of three years of archived social captions, pasted into one enormous document with no consistent formatting. She'd resigned herself to a weekend of manual highlighting until I sent her a single line — a regular expression matching any word starting with a hash symbol — that pulled every one of them out in under a minute. She still doesn't consider herself technical. She just keeps that one line, and four others like it, saved in a notes file she reuses constantly.

Forget the computer-science framing entirely

A regular expression is simply a compact way to describe a shape of text rather than one exact string. Instead of searching for the literal word 'invoice', you can search for 'any sequence of digits that looks like an invoice number' or 'any line ending in a question mark.' It's search-and-replace with a far richer vocabulary for describing what you're actually looking for, and once a handful of shapes click mentally, it's almost always faster than scrolling and highlighting by eye.

Five symbols that cover most everyday needs

You don't need the entire specification, and trying to learn it all at once is exactly why most people give up. These five cover the overwhelming majority of real tasks: a dot (.) matches any single character; \d matches any digit; a plus sign (+) means 'one or more of whatever came immediately before it'; square brackets like [A-Za-z] mean 'any character within this range'; and parentheses group part of a pattern so you can isolate or reuse just that section. Combined, these five already let you build patterns that catch most phone numbers, email addresses, and dates.

Building a phone-number pattern from scratch

A pattern like \d{3}[-.\s]?\d{3}[-.\s]?\d{4} catches a ten-digit US number formatted as 555-123-4567, 555.123.4567, 555 123 4567, or with no separator at all. \d{3} means exactly three digits in a row; [-.\s]? means an optional dash, dot, or space sitting between groups. That single pattern solves the overwhelming majority of real-world phone-number extraction tasks people actually run into.

Building an email-shaped pattern

A reasonably solid, non-exhaustive pattern for spotting email addresses looks like [\w.+-]+@[\w-]+\.[a-zA-Z]{2,}. Read left to right: one or more letters, digits, dots, plus signs, or hyphens, then an @ symbol, then more letters/digits/hyphens, then a literal dot, then at least two letters for the domain ending. It won't validate every technically permitted address under the formal specification, but it correctly flags the vast majority of real addresses and obvious typos, which is what actually matters for cleaning up a list rather than validating inbound mail server traffic.

Never trust a pattern you haven't tested

Writing a regex pattern and pasting it straight into a production dataset without testing it first is asking for trouble. Test against real sample text and watch exactly which characters get captured and which get missed. A regex tester that highlights matches live as you type turns an abstract, error-prone guessing exercise into something you can visually confirm within seconds, which matters enormously once a pattern grows past a handful of characters and small mistakes become genuinely hard to spot by eye.

The greedy-matching trap that catches almost everyone once

By default, a pattern like ".*" applied to a line containing multiple quoted sections will grab everything from the very first quote mark to the very last one in the line, rather than stopping at the nearest closing quote, because the star operator is greedy by default and grabs as much as it possibly can. Adding a question mark after it (".*?") makes it lazy instead, stopping at the first match found. A second common trap: characters like the dot, parenthesis, and dollar sign carry special meaning in regex, so matching them literally requires escaping with a backslash.

Knowing when regex is overkill

If you're searching for one exact, known phrase, a plain search-and-replace is faster and far less error-prone — there's no reason to build a pattern for something a literal string match already handles cleanly. Regex earns its complexity specifically when what you're looking for varies in a describable shape: any date, any number of a given length, any line matching a structure rather than an exact wording. Reach for it once plain find-and-replace keeps failing because your input just isn't consistent enough for an exact match.

A pocket glossary for reading someone else's pattern

^ anchors a match to the start of a line; $ anchors it to the end; \s matches any whitespace character including tabs and line breaks; a pipe symbol | means 'or', letting you match one alternative or another; and curly braces like {2,4} specify a repeat-count range, so a{2,4} matches 'aa', 'aaa', or 'aaaa' but not a single 'a' or five in a row. Keeping this glossary handy makes reading someone else's regex — in a forum post, a colleague's formula, or documentation — far less intimidating than starting from zero every time.

The questions people ask right after their first working pattern

Do I need to memorize the full regex syntax to be useful with it? No — the five building blocks above, combined with the habit of testing live against sample text, cover most non-programmer tasks like cleaning spreadsheets, validating form fields, or searching long documents.

Why is my pattern matching too much or too little text? This is almost always the greedy-versus-lazy issue described above, or a missing escape character on a symbol with special regex meaning. Building the pattern incrementally, one piece at a time, isolates the exact problem fast.

Can regex fully validate something like a phone number or email address? Not with complete certainty for every edge case the formal specifications technically allow, but a well-built pattern catches the overwhelming majority of real-world formatting issues, which is usually the actual goal in everyday cleanup work.

Does the same regex syntax work identically across every tool? Mostly, but not perfectly — small differences exist between regex flavors, particularly around lookaheads and Unicode character classes, so a pattern built for one tool may need a small adjustment elsewhere. Testing directly in the tool you'll actually use avoids surprises.