A book about patterns and decisions

The Shape
of Patterns

Learning to see structure through regular expressions

Regex is the subject. Judgment is the lesson.

Learn regular expressions from the ground up, then use them to practice something larger: defining problems, testing assumptions, managing complexity, and choosing the right tool.

# Start with the problem
^                  # Find the boundary
(?<structure>      # Name what matters
  observe          # See the problem
  | define         # Define the problem
  | decompose      # Figure it out
  | verify         # Test the solution

  #-------------
  # Learn to write readable regex, how to think 
  # about problems, or even just look at me 
  # attempt to explain recursion. 
  # ------------
)
$              # Know where to stop

Readable first. Compact later.

The larger lesson

The hard part is not the regex. It is understanding the problem.

Most regex books teach you how to write patterns. The Shape of Patterns teaches you how to think about a problem and uses regex as a visible, testable way to practice the habits behind mature technical work.

Learn the pattern, not just the syntax

The syntax gets more advanced. More importantly, so do the decisions.

01

What am I actually solving?

Begin with the data, the boundaries, and the rule instead of reaching immediately for symbols.

02

How will I know it works?

Use examples, counterexamples, edge cases, returned spans, and captures to test what the pattern truly promises.

03

What happens when it fails?

Reason about ambiguity, performance, false positives, false negatives, and operational consequences.

04

Who inherits this later?

Make intent, assumptions, ownership, and tradeoffs visible enough for another person to understand and change safely.

05

Does the environment change the answer?

Understand engines, host operations, compatibility, performance models, and the cost of specialized features.

06

Should regex own this problem?

Compare regex with literal string operations, ordinary code, parsers, libraries, and staged solutions.

A progression toward maturity

You come in wanting to understand regex.

You leave with a repeatable way to approach unfamiliar technical problems.

  1. 01
    See the structure

    Characters, positions, boundaries, categories, repetition, and readable patterns.

  2. 02
    Define the rule

    Examples, counterexamples, decomposition, expression, verification, and maintenance.

  3. 03
    Work in the real world

    Code, terminals, editors, logs, security, automation, analytics, spreadsheets, and databases.

  4. 04
    Understand the machinery

    Engines, compatibility, backtracking, predictable execution, and performance tradeoffs.

  5. 05
    Make the decision

    Reliability, tool choice, failure behavior, ownership, restraint, and judgment.

  6. 06
    When Regular Expressions aren't the answer

    Consider alternative approaches for text processing and pattern matching.

Wherever you are with regex

Start from understanding.

New to regex?

Build a mental model before the symbols become intimidating. Learn why patterns work, not just what to type.

Use it occasionally?

Stop relearning isolated tricks. Develop a process you can carry from one problem and tool to the next.

Already experienced?

Go beyond syntax into engines, performance, maintenance, compatibility, ownership, restraint, and judgment.

The payoff

The pattern did not become simpler. You became more fluent.

At first, a complicated regex looks like punctuation. Later, you see components, relationships, boundaries, and decisions. The goal is not to memorize every feature. It is to know how to begin.

“I can figure this out.”

Where this way of thinking came from

Experience with systems, risk, projects, and people.

Chris Forsythe has worked in Cybersecurity and IT Security for more than 20 years. He is a co-founder of Growl and Perian and formerly served as Project Manager for Adium.

His work in open source was centered on helping projects and people move forward: community building, technical communication, release management, product direction, and making complex decisions understandable.

Over time, the hardest questions stopped being purely technical. What are we trying to accomplish? What are we assuming? What happens when we are wrong? Can someone else maintain what we built? Is the technically interesting solution actually the right one?

Regex gave him a language for teaching those questions.

Regex is the vehicle.

Learning how to think about patterns is the destination.

Follow the book

Want to know when it is ready?

I'm writing a book, not starting a regex newsletter. Sign up for publication news and meaningful updates about The Shape of Patterns. I will not email you just because it is Tuesday.