apache/cassandra · error · ConstraintViolationException
Value does not match regular expression %s
Error message
Value does not match regular expression %s
What it means
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.
Source
Thrown at src/java/org/apache/cassandra/cql3/constraints/RegexpConstraint.java:60
private Pattern pattern;
public RegexpConstraint(List<String> args)
{
super(FUNCTION_NAME, args);
}
@Override
protected void internalEvaluate(AbstractType<?> valueType, Operator relationType, String regexp, ByteBuffer columnValue)
{
assert pattern != null;
Matcher matcher = pattern.matcher(valueType.getString(columnValue));
switch (relationType)
{
case EQ:
if (!matcher.matches())
throw new ConstraintViolationException(format("Value does not match regular expression %s", regexp));
break;
case NEQ:
if (matcher.matches())
throw new ConstraintViolationException(format("Value does match regular expression %s", regexp));
break;
default:
throw new IllegalStateException("Unsupported operator: " + relationType);
}
}
@Override
public List<AbstractType<?>> getSupportedTypes()
{
return SUPPORTED_TYPES;
}
@Override
public List<Operator> getSupportedOperators()View on GitHub (pinned to 88fd0f6a0e)
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.
Example fix
// constraint: CHECK email =~ '^.+@.+\..+$'
// before: INSERT INTO users (email) VALUES ('not-an-email'); -- rejected
// after
INSERT INTO users (email) VALUES ('user@example.com'); Defensive patterns
Strategy: validation
Validate before calling
// Java: pre-check with the same semantics as the constraint
if (!java.util.regex.Pattern.compile("^.+@.+\\..+$").matcher(email).matches())
throw new IllegalArgumentException("email does not match required pattern"); Try / catch
catch (ConstraintViolationException e) { log.warn("regexp constraint rejected value: {}", e.getMessage()); } Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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().
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Value does match regular expression %s
- Column value does not satisfy value constraint for column '<
- String '%s' is not a valid regular expression
- Column value does not satisfy value constraint for column '<
- category %s not found in %s
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/7d242404aed4ac8a.
Report an issue: GitHub.