Kafka Error INVALID_REGULAR_EXPRESSION
Error code 128 · Non-retriable KRaft
The regular expression is not valid.
Common Causes
- A regex pattern submitted to the broker (e.g., for topic subscription filtering or a KRaft metadata filter API) is syntactically invalid — contains unescaped special characters, unbalanced brackets, or unsupported regex features.
- Client-side regex validation is missing or uses a different regex dialect than the broker's Java `java.util.regex.Pattern`, causing patterns that are valid client-side to be rejected server-side.
- Dynamic configuration update or admin API call included a malformed regex string (e.g., an incomplete lookahead, invalid quantifier like `{,5}`).
Solutions
- Validate the regex with the same engine Kafka will use before sending it. For consumer-pattern subscriptions that usually means Java/RE2J-compatible syntax, not PCRE-specific extensions.
- Avoid advanced regex features that Kafka does not support in the relevant path; keep patterns simple and anchored so they compile consistently on both client and broker.
- If the regex was dynamically generated, add server-side validation at the application layer before the Kafka API call to catch and surface invalid patterns early.
Diagnostic Commands
# Check topic config for patterns
kafka-configs.sh --bootstrap-server localhost:9092 --describe --entity-type topics | grep -i 'pattern\|regex'
# Look for corruption or validation errors
grep 'INVALID_REGULAR_EXPRESSION\|regex\|Pattern' /var/log/kafka/server.log | tail -30Related APIs
This error can be returned by: EndTxn · InitProducerId · WriteTxnMarkers
Debugging Kafka errors? Conduktor Console gives you real-time visibility into your cluster. Explore all errors in the Error Decoder.