{"record":{"id":"7d242404aed4ac8a","repo":"apache/cassandra","slug":"value-does-not-match-regular-expression-s","errorCode":null,"errorMessage":"Value does not match regular expression %s","messagePattern":"Value does not match regular expression (.+?)","errorType":"validation","errorClass":"ConstraintViolationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/constraints/RegexpConstraint.java","lineNumber":60,"sourceCode":"\n    private Pattern pattern;\n\n    public RegexpConstraint(List<String> args)\n    {\n        super(FUNCTION_NAME, args);\n    }\n\n    @Override\n    protected void internalEvaluate(AbstractType<?> valueType, Operator relationType, String regexp, ByteBuffer columnValue)\n    {\n        assert pattern != null;\n        Matcher matcher = pattern.matcher(valueType.getString(columnValue));\n\n        switch (relationType)\n        {\n            case EQ:\n                if (!matcher.matches())\n                    throw new ConstraintViolationException(format(\"Value does not match regular expression %s\", regexp));\n                break;\n            case NEQ:\n                if (matcher.matches())\n                    throw new ConstraintViolationException(format(\"Value does match regular expression %s\", regexp));\n                break;\n            default:\n                throw new IllegalStateException(\"Unsupported operator: \" + relationType);\n        }\n    }\n\n    @Override\n    public List<AbstractType<?>> getSupportedTypes()\n    {\n        return SUPPORTED_TYPES;\n    }\n\n    @Override\n    public List<Operator> getSupportedOperators()","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/constraints/RegexpConstraint.java#L42-L78","documentation":"Thrown by RegexpConstraint.internalEvaluate when the relationType is EQ and the column value does NOT fully match the column's declared regular expression constraint. Cassandra evaluates regexp constraints on writes; a non-matching value raises ConstraintViolationException and the write is rejected.","triggerScenarios":"INSERT/UPDATE of a column constrained with a regexp EQ constraint where the value does not fully match the pattern (Matcher.matches() requires the whole string to match).","commonSituations":"Email/format-enforcement constraints where application data contains unnormalized values (leading/trailing whitespace, country codes in phone numbers, case differences); regex written expecting partial matching (find) instead of full-string matches().","solutions":["Correct the written value so it fully matches the constraint's regexp.","Verify the pattern assumes full-string matching (matches(), not find()); widen it, e.g. add '.*' wrappers, if partial matches should be accepted.","ALTER the table to drop or replace the regexp constraint if the rule is no longer appropriate."],"exampleFix":"// constraint: CHECK email =~ '^.+@.+\\..+$'\n// before: INSERT INTO users (email) VALUES ('not-an-email'); -- rejected\n// after\nINSERT INTO users (email) VALUES ('user@example.com');","handlingStrategy":"validation","validationCode":"// Java: pre-check with the same semantics as the constraint\nif (!java.util.regex.Pattern.compile(\"^.+@.+\\\\..+$\").matcher(email).matches())\n    throw new IllegalArgumentException(\"email does not match required pattern\");","typeGuard":null,"tryCatchPattern":"catch (ConstraintViolationException e) { log.warn(\"regexp constraint rejected value: {}\", e.getMessage()); }","preventionTips":["Keep a single source of truth for the pattern shared by app and schema.","Remember matches() is full-string, not partial.","Normalize input (trim, lowercase) before validating and writing."],"tags":["cassandra","cql","regexp","constraint-violation"],"backgroundTag":"schema-validation-failed","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}