ai-coding-minesIndexGitHub

In a list of patterns, the order is the priority

Python and databases

Symptom

Several rules classify a string by shape. The specific cases got swallowed by the general one.

matches 2-9-2 shape  -> A     <- general pattern first
starts with 1Z       -> B
starts with LS       -> C

Both 1Z... and LS...US match the general pattern first, so everything classifies as A. Rules B and C are never reached.

Fix

1Z, LS, 4PX  (specific prefixes)  <- first
2-9-2, N digits (general shapes)  <- after

In a pattern list, the written order is not documentation order — it is execution priority. Treat ordering as design.

Second time

The same shape had been hit before, in product classification: mount inside Rail-mounted matched "mount bracket", and pen inside Tactical Pen matched "fountain pen". A short general token placed first means the longer specific token is unreachable.

The mistake repeated in a different domain after being learned once. Every time you write a new rule list, check "is the specific one above?"