PassaTime
All stories
AI HELP · REGULAR EXPRESSIONS 2026-10-14

An AI regex finds “cat”. Does it also match “concatenate”?

Give the AI examples that must match and examples that must not. Run both groups in the language and flags you will actually use.

Define the intended match before asking for a regular expression. For this example, we want the standalone English word cat, ignoring case, but not cat inside another word or identifier.

Try the unwanted matches first

In our Node.js check, /cat/i matches both “cat” and “concatenate”. /\bcat\b/i matches “cat”, “Cat” and “cat!”, but rejects “concatenate”, “cat_food” and “cat3”. The underscore and digit cases are deliberate checks, not typos.

Say what a word means here

MDN documents JavaScript’s word characters as including Latin letters, digits and underscore, with additional case-folding behavior in certain modes. Its word boundary is not a general word detector for every language. Do not reuse this English example as a Korean-language segmentation rule.

Ask for a test list with the pattern

A useful request is: “Use JavaScript, ignore case, and return a pattern plus expected true/false results for these six strings.” Review those expectations yourself. Other languages, flags or requirements may need a different pattern.

Preview before replacing

If the next step deletes or replaces matching text, use a copy and inspect the matches first. A pattern that passes these six examples has passed those examples; it has not been proved correct for every possible input.

Published October 14, 2026. The two patterns and six original strings were executed in Node.js. No AI service generated them during this check, and no user files were changed.

Sources: MDN · Word boundaries.