An AI-generated regex matches the example. What about the rest of the data?
Assess an AI-generated regex through whole-value matching, input type, normalization and valid and invalid examples.
Article language: English

In this article
The code AB-1234 matches. Someone pasted an example into a conversation, and the assistant returned a short rule with an assurance that it checked the format. Then “xAB-1234” turns out to match too, as does a list containing that one code. The rule found the characters it was looking for. Nobody had established whether it was meant to find a fragment or accept exactly one valid text value.
This is our own working example. A regex, or regular expression, describes a pattern for matching characters. It can be very useful, but a short expression is not automatically easy to assess. A few characters can hide several decisions: which type of data is allowed, where to look for a match, what may be changed before assessment and how to handle difficult input. AI should not make those decisions for the process owner simply because they fit on one line.
Are we searching a sentence for a code or checking a field?
Both tasks can use a similar pattern, but they have different outcomes. When reading an order description, you may want to find a code among other words. When accepting an “order code” field, you may require exactly two uppercase Latin letters, a hyphen and four digits. For the first task, “please check AB-1234” is valid material to search. For the second, it does not meet the agreed format for the whole field.
MDN describes input boundaries in JavaScript regular expressions. Start and end markers restrict where a match can occur, while multiline mode changes their meaning to line boundaries. Assess a pattern together with the mode and the way it is called. A picture of the rule alone does not show every condition under which it runs.
Before asking AI for a solution, write down the expected outcome for several inputs. For the code field, decide whether to allow spaces at the edges, lowercase letters, a line break or an extra comment. If you want to accept them after a transformation, name that as a separate step. Do not derive the acceptance rule from incidental program responses. Expectations should come before implementation.
Pair negative examples with positive ones. Starting with AB-1234, change the number of digits, the position of the hyphen and the case of one letter separately. In another input, keep the valid middle but add a character at the end. That lets you identify which rule each case breaks. If five things change at once, a rejection says little about the effectiveness of each check. Record the reason alongside the expectation, so a later pattern change does not turn invalid input into a new standard merely because it now passes.
In a small isolated trial conducted for this article, a pattern looking for two letters, a hyphen and four digits also found a match inside “xAB-1234”. The version restricted to the whole value, /^[A-Z]{2}-[0-9]{4}$/ without additional flags, rejected that prefix. This is the result of a simple Node.js example without external services or customer data. It does not prove that every regex is correct, and it is not a test of your form. It shows why one positive example does not settle the task.
Also test the same valid input repeatedly. MDN's description of RegExp.test explains that expressions with the global or sticky flag, which use a remembered match position, retain state from a previous call. Do not choose a flag simply because it appeared in an assistant's answer. A field requirement usually concerns the value, not how many times the method has already been called. This additional scenario needs checking in your own solution; it was not part of the eight-case trial described here.
Write down what result the user should receive too. A code search benefits from the matched fragment and its position in the text. Validation, meaning a check that the field meets the requirement, needs an accept-or-reject decision and an understandable reason. If a program simply returns empty text after a failed match, a later step may confuse an input error with missing optional information.
Why check the data type separately?
Today a field arrives as text from a form, but tomorrow an integration may send it. Its response might contain an array, a number or an object instead of a single string. If the agreed format calls for text, rejection of another type should be explicit. It is not enough that the program can convert the received value into something resembling text and then compare it with the pattern.
The JavaScript RegExp.test documentation explains that supplied values are converted to strings. A successful match therefore does not establish the argument's original type. That is a specific behavior of this method, not a universal rule for every language and library that uses regular expressions.
In our local trial, an array containing only “AB-1234” passed the whole-value pattern check on its own. It was rejected after an explicit text-type requirement was added. This result applies to the specific example retained for the trial. In your system, check the actual path of the data: what the browser sends, what the server receives and whether an earlier layer has already performed a conversion.
The test set should include text, empty text, a missing value, an array and a number if they can cross the input boundary. For each case, record an expectation consistent with the contract. A number that looks like a code is not necessarily a valid code. Automatic conversion may be a deliberate solution for another task, but then it needs to be described and tested, not obtained accidentally as a convenience of the method.
The article on valid JSON and incorrect meaning in AI data (in Polish) explores input structure further. A regex alone should not replace a schema for the whole response. Checking a field's structure, the existence of an order and permission to change it are separate questions. Even a perfectly formatted AB-1234 does not prove that the order exists or may be edited.
When do we transform the value and when do we reject it?
The process owner may allow spaces at the edges of a code to be removed or letters to be changed to uppercase. In another field, that could alter a value that should have been left alone. Set the policy before validation and distinguish the original input from the value used. Do not describe automatic removal of arbitrary characters as harmless “cleaning” if it can merge two different identifiers.
OWASP's input validation guide recommends explicit Unicode rules, whole-value matching for simple fields and tests with valid, invalid and near-matching data. It also stresses that normalization does not replace other security controls. The rules depend on what the particular field means.

In the working code, the letter O and the digit 0 can look similar, but they are not automatically interchangeable. If AI proposes replacing one with the other, ask which requirement justifies it. The same applies to similar hyphens and letters from different alphabets. A helpful message such as “check the code” may be more sensible than independently creating a different identifier the user never provided.
For free-form fields such as a person's name or a project description, do not transfer the rule from our narrow code. Restricting input to Latin letters without diacritics can reject a person's valid data. First identify the business need and the languages actually supported. A pattern that guards seven characters of a technical identifier does not thereby become a good guard for all correspondence.
Check the order of operations where the rule is actually used. If the screen trims spaces but the server does not, the two stages can make different decisions about an apparently identical field. Keep selected examples for an integration that bypasses the screen as well. Acceptance should show consistent results for the inputs within scope, without assuming that every user always goes through the form.
Does difficult input stay within the available work limits?
A quick match on a short example does not establish the cost of every allowed input. The Node.js guide to blocking the event loop describes expressions for which a difficult non-match can require disproportionate work. The event loop coordinates handling; blocking it can affect other users of the application. The assessment depends on the pattern and execution engine.
During acceptance, establish the maximum length and kinds of material reaching the rule. Only then select execution-cost tests for that scope with the person responsible for the code. No single character limit suits a code field, a description and a large document. A limit should follow from the task's needs and be checked before expensive processing begins. Shortening data only after matching does not limit work already performed.
Run difficult tests in a controlled, isolated environment with a way to stop them. Do not send growing inputs to a customer's live form as a spontaneous “AI check”. This kind of assessment requires an agreed scope, conditions and appropriate expertise. The eight-case trial described earlier was not a load measurement or a denial-of-service resilience test and must not be presented as one.
If the assistant proposes an additional package or a replacement matching engine, check the dependency's origin and compatibility. The article on AI-suggested libraries that may not exist (in Polish) addresses that boundary. A new dependency does not remove the need to repeat the examples: different solutions may interpret characters, flags and pattern syntax differently.
What belongs in the acceptance evidence for a small rule?
Keep the requirement, the actual pattern used, flags, environment version and the input set with expectations and results. Our example used eight artificial cases, including a code, a prefix, a suffix, an array, a number and a line break. It also checked that the simpler variant admitted the specified unwanted inputs. This trail shows which problem the fix distinguished instead of stopping at a green message.
The article “AI says the tests passed” (in Polish) develops the evidence of execution and strength of a check. That includes the exact command and assertions, meaning comparisons of results with expectations. Here the assessment also concerns the rule's meaning: fragment, whole value, type and transformations. Do not combine those questions under the single label “the format works”.
Pin the record to a specific version of the file. A hash in an AI report (in Polish) helps distinguish copies, but it does not make a pattern correct. After a requirement or execution mode changes, return to the retained cases. Valid input should still pass, and rejected input should not start passing by accident. If an expectation changes deliberately, record the reason separately.
If accepting the field opens the way to further agent actions, also control the response to rejection. An invalid value should not trigger part of the operation through another route. The discussion of partial execution across several systems (in Polish) can help. A small rule can be the start of a decision with much larger consequences, so relate its acceptance condition to the actual use.
Before using a stricter rule, also review an in-scope sample of data already stored in the process. Decide what to do with older codes that the new condition will reject. Data correction, separate handling of an old format or clarification of the requirement may be needed. Not every rejection by a new version is an improvement. The process owner should know the effect on existing cases before a simple change starts blocking daily work. Keep those decisions with the examples.
The operational scope of this assessment can be agreed with Aeneia Audit. Reviewing AI use and reported evidence does not automatically amount to a specialist security audit of the entire application.
Aeneia Audit
Bring requirements, test cases and evidence for rules prepared by an AI assistant into order before they enter a daily process. Discuss an assessment of a coding assistant's work.
Primary sources were checked on 30 October 2026. The local trial covered only artificial data and simple rules; no tests were run on other parties' systems.







