G-XR8P2XJ088

AI-Written Regex: Test What It Must Reject

An AI-generated pattern looks convincing when it recognises your example. The more revealing test is whether it rejects a value that is almost right. An extra digit, a different dash or a reference buried inside a sentence can expose a mismatch between the rule you intended and the operation you actually ran.

A regular expression, often shortened to regex, describes a text pattern. For a creator or business owner using one to check imported records, the useful deliverable is a clear acceptance rule, a compatible implementation and examples that demonstrate its boundaries.

The worked example here uses a fictional studio’s edition references. It checks their format; it does not establish that an edition actually exists.

Write the rule before asking for the pattern

The studio wants references consisting of uppercase ART, one ordinary hyphen and exactly three digits from 0 to 9. The entire field must follow that format. Leading or trailing spaces, extra text and line breaks are unacceptable. For this example, 000 is allowed.

Those decisions produce clear examples: ART-204, ART-000 and ART-999 should pass. They also prevent the AI from silently deciding that lowercase letters are acceptable or that leading zeroes should disappear.

Give the rule and its purpose together. Checking whether a field contains only a reference is different from finding a reference somewhere in an email. Both can be useful tasks, but they need different acceptance tests.

Choose the operation as well as the expression

For the studio’s Python check, use the pattern ART-[0-9]{3}.

The Python documentation distinguishes re.search(), which looks for a match anywhere in the text, from re.fullmatch(), which checks the whole string. Assuming value is text and the re module has been imported, the example check is:

re.fullmatch(r"ART-[0-9]{3}", value) is not None

With the same pattern, a search finds a reference inside booking ART-204 confirmed. The whole-field check rejects that sentence. The pattern’s appearance alone therefore cannot tell you whether the complete validation rule has been implemented.

These Python examples were checked in Python 3.12.14. That verifies the stated cases in that environment; the next step for an actual workflow is to run its examples where the pattern will be used.

Build the rejection examples deliberately

Start with accepted examples, then change one feature at a time. That makes a failure easier to explain. For the studio’s rule, the following should all be rejected:

  • ART-20 and ART-0204: too few or too many digits.
  • art-204: the prefix is lowercase.
  • xART-204 and ART-204x: unwanted text surrounds the reference.
  • ART–204: the separator is an en dash, rather than the specified hyphen.
  • A value with a space before or after ART-204, or a line break after it: the field contains additional characters.

Keep the expected result beside each example before running the test. If the actual result differs, ask whether the expression, matching operation or original rule needs changing. Do not revise an expected rejection merely because the generated pattern accepts it.

Make the meaning of “digit” explicit

Python’s documentation says that \d in a Unicode text pattern includes Unicode decimal digits beyond 0–9. Consequently, a Python whole-string check using ART-\d{3} accepts ART-٢٠٤, whose digits are Arabic-Indic. The explicit [0-9] range rejects it under our fictional rule.

That rejection is a requirement of this particular reference format. It is not a reason to prohibit someone’s language or writing system in unrelated fields. A name, address or free-text response needs its own requirements; importing this narrow rule into those fields would answer the wrong question.

An awkward example is useful because it forces an owner to make a choice. If the studio actually wants several numeral systems, change the specification and examples openly, then choose an implementation that supports them.

Check the destination app

Google’s REGEXMATCH documentation says Google Sheets uses RE2, with a limitation on Unicode character-class matching. The function takes text and returns TRUE or FALSE. It should not be treated as an interchangeable wrapper around Python’s matching functions.

For the fictional reference stored as text in A2, a Google Sheets version using comma-separated formula syntax is =REGEXMATCH(A2,"^ART-[0-9]{3}$"). Keep the result in another cell so the original value remains available for inspection.

The RE2 syntax reference defines the start and end assertions used here. With multiline mode off, they constrain the match to the text’s beginning and end. Its documentation also lists supported features and flags. When moving a pattern between apps, check that destination’s rules and rerun the examples.

Keep checking separate from changing

Suppose the studio decides a trailing space should be removed before checking. That is an additional processing step and a changed rule for handling input. Record it explicitly. A test on the cleaned value cannot show that the original field already had the required format.

For a trial run, report pass or fail alongside the original text. Review rejected examples before using the result to exclude records or route work. A format failure is a prompt to investigate the value, not an explanation of how it became different.

A reference such as ART-000 could pass the format check while remaining unassigned in the studio’s catalogue. If the next action requires an active edition, compare the value with the studio’s approved records as a separate step. The pattern alone has no information about those records.

Save the rule with the tests

Keep the written specification, destination app, pattern, matching operation and expected examples together. Add a new case whenever a real ambiguity appears. After an edit, inspect which outcomes changed; fixing one rejection should not quietly reverse an unrelated decision.

MaryChuks.com’s guide to a repeatable AI run sheet offers a useful place for that record. The practical aim is a check another person can understand and reproduce, including what it deliberately leaves unanswered.

Sources

Documentation checked on 25 October 2026. The studio’s edition references and test values are illustrative.


Discover more from Marychuks.com AI, Psychology, Business & CreativeVerse

Subscribe to get the latest posts sent to your email.

Leave a Reply

Discover more from Marychuks.com AI, Psychology, Business & CreativeVerse

Subscribe now to keep reading and get access to the full archive.

Continue reading

Discover more from Marychuks.com AI, Psychology, Business & CreativeVerse

Subscribe now to keep reading and get access to the full archive.

Continue reading