C.W.K.
Stream
Lesson 06 of 10 · published

Testing Tools — Your Regex Microscope

~8 min · tools, regex101, debuggex

Level 0Pattern-Curious
0 XP0/90 lessons0/15 achievements
0/100 XP to next level100 XP to go0% complete

Don't write regex without a sandbox

Trying to write a non-trivial regex straight into your code is like trying to debug a SQL query without a REPL. You can do it. You shouldn't.

Pro habit: build the pattern in a tester, paste it into your code only when it works.

Three testers worth knowing

regex101.com — the standard. Pick a flavor (PCRE2, Python, JavaScript, Go), paste your pattern, paste your test strings, see live highlighting, named-group breakdown, step-by-step explanation, and a debugger that walks the engine state. Free. No login needed for basic use.

regexr.com — friendlier UI, slightly less detail. Good for quick checks.

debuggex.com — visualizes your pattern as a railroad diagram (the state machine from lesson 4 made visible). Useful when you're trying to *understand* a complex pattern, not just test it.

Built-in alternatives

If you live in a terminal, your tester is one of:

  • rg --debug 'PAT' file — see what RE2 thinks.
  • Python REPL: import re; re.findall(r'PAT', text) — fastest sandbox if Python is your daily driver.
  • echo "input" | grep -E 'PAT' — POSIX-only check.

Build patterns incrementally

Don't try to write the perfect 80-character pattern in one shot. Start with the simplest version that matches one example. Add specificity. Test. Add an edge case. Test. The pattern grows from a seed, not from a blueprint.

Code

Incremental pattern-building in the Python REPL·python
>>> import re
>>> text = 'Order #42-1138 placed on 2026-05-04'
>>> # Step 1: just the order number area
>>> re.findall(r'#\d+', text)
['#42']
>>> # Step 2: include the dash and second number
>>> re.findall(r'#\d+-\d+', text)
['#42-1138']
>>> # Step 3: capture both parts separately
>>> re.findall(r'#(\d+)-(\d+)', text)
[('42', '1138')]

External links

Exercise

Pick the most complex regex you can find in your codebase (search for re.compile, RegExp, or .match(/). Paste it into regex101 with the matching flavor. Read the explanation pane. Did you actually understand all of the pattern before? Most people discover at least one piece they were guessing about.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.