Test an AI regular expression on examples you already classified

Mark match / no-match rows first. Run the pattern in your app’s engine. Keep it only when every row matches your mark.

Published 2026-11-22 · Translation: VI

In short

  • Write your examples before you ask: each string is already “match” or “no”.
  • Name the engine the app will use (re in Python, or JavaScript RegExp).
  • Run every row with the same call the app will use. Keep the pattern only when every row hits your mark.

Contract for this page (invented codes): whole string is INV, optional case, a hyphen, and exactly four characters 0–9. Spaces, extra digits, extra, and non-ASCII digits are all “no”.

A chat can return INV-\d{4} and show that INV-1042 matches. That row is easy. The “no” rows are the real check.

Marks first → correct engine → every row on its mark → keep the pattern.

Order matters: classify first, then ask, then run.

Run the examples in the app’s engine

Python 3.12.3 and Node v22.23.4 (22 November 2026). Pattern INV-\d{4} with case-insensitive flag. “Yes” means the call found a match.

String Mark re.search re.match re.fullmatch JS test()
INV-1042 match yes yes yes yes
inv-1042 match yes yes yes yes
INV-1042 extra no yes yes no yes
xx INV-1042 no yes no no yes
INV-1042 + newline no yes yes no yes
INV- + Arabic-Indic digits no yes yes yes no
INV-10421 no yes yes no yes
space + INV-1042 no yes no no yes
INV-104 no no no no no
INVOICE-1042 no no no no no
empty no no no no no

re.search / JS test() without anchors accept a match inside a longer string. re.fullmatch and /^…$/ require the whole string.

Python \d matches any Unicode decimal digit; JS \d is [0-9]. Use [0-9] when you mean ASCII digits only.

Calls that hit every mark on this list:

import re
kept = re.compile(r"INV-[0-9]{4}", re.IGNORECASE)
# kept.fullmatch(text) is not None
const kept = /^INV-[0-9]{4}$/i;
// kept.test(text) on a fresh RegExp each row; no g or m

Misses: re.match accepts trailing text; $ can still allow a trailing newline in Python search; /g advances lastIndex so a second test() fails.

Arabic-Indic digits are a fourth miss on Python \d — mark is no; JavaScript \d already says no.

Send the miss back with the whole list

Fixing one row can break another. Send pattern, call, row, mark, and ask for a pattern that passes every row.

Engine: Python 3.12, re
Pattern: INV-\d{4}
Call: re.search, re.IGNORECASE
Row: INV-1042 extra
Mark: no
Result: search returned INV-1042 at span (0, 8)
Next pattern: pass every row, including the ones that already passed.

On this list the next Python call was re.fullmatch of INV-[0-9]{4} with re.IGNORECASE. JavaScript: /^INV-[0-9]{4}$/i without g or m.

Miss goes back with the whole list → re-run every row → all marks match → keep.

Name the call (fullmatch vs search) as well as the pattern text.

Watch-outs

  • Python 3.12 has no re.prefixmatch. Prefer fullmatch for “whole string.” \Z is end-only; \z needs newer Python.
  • g and m change results. Global test() advances lastIndex. m makes $ match before newlines.
  • An online tester is a third engine. Re-run in the library your app imports.
  • Keep real order numbers out of the chat. Use invented codes in the same shape.

Share

X Facebook LinkedIn
Educational content only. Rankings reflect stated criteria at the update date—not investment advice or permanent performance guarantees.