CaseConvert
Home/Blog/Regex Basics Every Writer Should Know
Productivity

Regex Basics Every Writer Should Know

Regular expressions aren't just for developers. Five simple patterns can save any writer hours of find-and-replace drudgery.

CC
The CaseConvert Team
September 2, 2025 9 min read

The mental model

A regex is a tiny pattern language. Instead of searching for one exact string, you describe *what the text looks like* and let the engine find matches.

Five patterns worth memorizing

  • \s+ — one or more whitespace characters (great for collapsing double spaces).
  • \d+ — one or more digits.
  • [A-Z][a-z]+ — a capitalized word.
  • ^\s+|\s+$ — leading and trailing whitespace.
  • (\w+)\s+\1 — a repeated word (great for finding "the the" typos).

Try them safely

Our Find and Replace Text tool supports regex mode with live highlighting, so you can iterate without breaking your draft.

One tip

Always test a regex on a copy first. Small patterns can match more than you expect.

Five more patterns for everyday editing

  • [""''] — matches curly quotes of either kind, so you can normalise them to straight quotes before sending text to a system that cannot handle them.
  • \.{2,} — two or more full stops, which finds accidental "...." and inconsistent ellipses.
  • \b(\w+)\b(?=.*\b\1\b) — flags a word that appears again later in the same line, useful for spotting repetition in headlines.
  • ^\s*[-*]\s+ — the start of a bullet list item, handy for converting between list markers.
  • \s+([,.;:!?]) — a space before punctuation, one of the most common artefacts of hand-edited text.

Replacement patterns

Half the value of regex is in the replacement side. Capture groups let you rearrange text rather than just delete it. A group is anything in parentheses, and you refer back to it in the replacement as $1, $2, and so on.

  • Find (\w+),\s*(\w+) and replace with $2 $1 to turn "Smith, John" into "John Smith".
  • Find (\d{4})-(\d{2})-(\d{2}) and replace with $3/$2/$1 to convert ISO dates to day-first format.
  • Find \s+ and replace with a single space to collapse all runs of whitespace.

Greedy versus lazy matching

.* is greedy: it matches as much as it can and then backs off. In <b>one</b> and <b>two</b>, the pattern <b>.*</b> matches the entire line, not the first tag pair. Adding a question mark makes it lazy — <b>.*?</b> stops at the first closing tag. This single character is behind most "my regex matched too much" surprises.

Rules that prevent damage

  1. Test on a copy. Always. A bad replacement across a whole document is rarely undoable in one step.
  2. Preview matches before replacing. Highlighting shows you what a pattern really selects, which is frequently not what you intended.
  3. Anchor when you can. ^ and $ restrict a pattern to the start or end of a line and prevent accidental mid-line matches.
  4. Escape special characters. A literal full stop is \.; an unescaped . matches anything.
  5. Build patterns incrementally. Start with the simplest version that matches, then tighten it.
  6. Do not parse HTML with regex. Use it for small, flat clean-ups; nested markup needs a real parser.

Where regex is the wrong tool

If the task involves matching nested structures, understanding grammar, or making judgement calls about meaning, regex will produce a pattern that is longer than the text it processes and impossible to maintain. Straightforward find-and-replace, a spellchecker, or a short script is usually the better answer. Regex earns its keep on repetitive, well-defined, single-line patterns — and there it saves hours.

Practise safely with regex mode in our Find and Replace Text tool, which highlights matches live before you commit a replacement.

Found this useful?
Share it with someone who'd like it.
Share