AI Anonymous / Practical field guide / November 5, 2026

Your AI regex matched too much.

A convincing answer and one passing example can hide a pattern that collects the wrong text. Give the draft a second label before using it.

In this field note · 7 sections
  1. Inspect the returned text
  2. A shorter match still needs a rule
  3. Keep both accepted and rejected examples
  4. Change the examples before the pattern
  5. Know what ten examples establish
  6. Read the Python documentation
  7. Keep the lab or share the field note

Imagine asking an assistant for a Python regex to extract labels from a note. Your example is [RED]. The draft r"\[.*\]" appears to work. Now try [RED] [BLUE]: the draft returns one combined match.

What we ran. Ten authored, fictional extraction cases on Windows with Python 3.13.15 and its standard-library re module. The draft matched our expected lists in 5 cases, the minimal-match variant in 7, and the reviewed pattern in all 10. These are fixture counts. We did not call a model, capture a real assistant response, or measure performance.
AI Anonymous poster reading Your AI regex matched too much. A single copper highlight spans RED and BLUE bracket labels; two separate outlines below enclose one label each. Footer: Test the second example. JABSystems.
Original AI-generated editorial illustration; conceptual matches, not a software screenshot.

01 / Reproduce

Inspect the returned text

Use Python 3.10 or newer. Copy this complete snippet into a scratch Python file and run it. It reads only the string shown here.

import re

text = "[RED] [BLUE]"
print(re.findall(r"\[.*\]", text))
print(re.findall(r"\[.*?\]", text))
print(re.findall(r"\[[A-Z]+\]", text))

Our run printed:

['[RED] [BLUE]']
['[RED]', '[BLUE]']
['[RED]', '[BLUE]']

In Python, .* is greedy: it consumes as much as it can while the remaining pattern still matches. The closing bracket can therefore be the last one on this line. .*? tries a shorter match. The raw-string prefix keeps the backslashes for the regex engine. Python regex syntax.

02 / Define

A shorter match still needs a rule

For this fictional workflow, a label contains one or more ASCII uppercase letters inside square brackets. Keep the brackets and source order. Empty labels, lowercase letters, numbers and newlines inside a label do not qualify. Ordinary text may appear between labels.

The minimal variant separates the two labels, but also returns [], [red] and [R2D2]. Each conflicts with this policy. The reviewed pattern r"\[[A-Z]+\]" makes that alphabet and the minimum length explicit.

This policy is our example's requirement. Your project might legitimately allow numbers or mixed case. Define that requirement before asking an assistant to revise a pattern.

03 / Run and review

Keep both accepted and rejected examples

Download the practice ZIP above and extract it into a fresh folder. Open PowerShell in the extracted folder and run:

python .\check-labels.py

No package installation, account or API key is needed. The script writes observed-results.json in your current folder; the ZIP includes our recorded report for comparison. Its Python version records the runtime that produced it.

{"case_count": 10, "passed": {"draft": 5, "minimal": 7, "reviewed": 10}}

The ten cases cover one label, two separated labels, adjacent labels, ordinary text, empty brackets, lowercase, digits, a newline inside a label, a newline between labels and a missing closing bracket. Read the actual lists in the report, including the empty lists. The runner asserts every reviewed result and the three summary counts, exiting unsuccessfully if those checks disagree.

findall returns non-overlapping matches. These patterns have no capturing groups, so the result contains whole matched tokens. None uses DOTALL; dot does not cross a newline in this run. Python findall reference.

04 / Make it your own

Change the examples before the pattern

  1. Add [RED-BLUE], [Red] and [R2D2] to the fixture list. Write each expected list first. Decide whether hyphens, case and digits belong in your format.
  2. Ask your assistant to explain the current matches against that written policy. Give it the Python version and redacted examples. A proposed review prompt is in the README; we have not run that prompt against a model.
  3. Inspect the proposed pattern, rerun the fixture list, and review every changed output. When extending the supplied lab, deliberately update its pinned ten-case summary assertion as the README explains.

For a nontechnical review, the same habit works in a spreadsheet: write the input, expected extracted labels and actual labels in three columns. A visible mismatch is a useful question to take back to whoever owns the extraction.

Boundaries

Know what ten examples establish

This is substring extraction. It does not validate a complete note: a matching token inside a larger malformed structure can still be returned. If you need an entire field to follow a grammar, define that separate requirement and consider fullmatch. The lab does not establish nested-bracket handling, semantic correctness, all Unicode rules, resilience to hostile input or production readiness.

These are plain fictional labels. HTML and XML require their own parsing tools; changing greediness is not a general markup parser. Python's regex HOWTO explains that boundary. We tested no real model outputs, agent integration, large documents, other regex engines or timing. Python syntax and behavior should be checked again if you move this into JavaScript or another engine.

Primary sources / Checked November 5, 2026

Read the Python documentation

Downloads / Practice files

Keep the lab or share the field note

Explore more AI Anonymous field notes →

Share this post.

Found this useful? Pass it along. Download the artwork, add your own take, and tag @jabsystems.io so I can see your post.