MySQL error 1139 (ER_REGEXP_ERROR) appears when a REGEXP or RLIKE pattern is syntactically invalid or uses features not supported by the server.
MySQL Error 1139: ER_REGEXP_ERROR arises from an invalid regular expression in a REGEXP/RLIKE clause. Validate and correct the pattern or escape special characters to resolve the issue.
Got error '%s' from regexp
Error 1139 occurs when MySQL fails to compile the regular expression supplied to REGEXP, RLIKE, REGEXP_LIKE or a related function. The message includes a secondary string that pinpoints the internal PCRE error.
The server halts query execution at the failing clause.
Although the error sounds minor, it blocks inserts, updates and reads that rely on pattern matching, so quick remediation is vital.
Most cases trace back to malformed patterns such as unmatched brackets, unescaped metacharacters, improper repetition tokens or unsupported PCRE options.
The error also appears when a pattern length exceeds the PCRE engine limit, the server version lacks a specific syntax feature, or the query uses a non-UTF8 character incorrectly.
First isolate the pattern that triggered the error by running the REGEXP clause alone.
Then rewrite the expression with proper escapes and balanced delimiters. Use test queries to confirm the fix.
Upgrade to MySQL 8.0 or later if you rely on modern PCRE2 features. For legacy servers, refactor to simpler syntax or split complex patterns into multiple predicates.
Unescaped backslash in Windows file paths is common. Double the backslash or prefix with another escape to solve this.
Brackets left open in a dynamic query string will trigger 1139.
Validate user-supplied fragments before concatenation to prevent runtime errors.
Validate patterns with REGEXP_LIKE on a test string before using them in DML or DDL.
Store reusable patterns in variables or columns that your development team unit-tests and code-reviews.
Error 1138 (ER_REGEXP) signals an empty pattern, which differs from 1139’s invalid pattern. The remediation is similar: supply a valid, non-empty string.
Error 1267 (Illegal mix of collations) will appear if the pattern collation conflicts with the column.
Convert both operands to the same collation.
.
MySQL 8.0 and later support most PCRE2 constructs. Earlier versions raise ER_REGEXP_ERROR for unsupported syntax.
Test against a dummy string with REGEXP_LIKE. Galaxy’s editor highlights errors inline, speeding up debugging.
No. sql_mode does not influence the PCRE compiler. You must correct or simplify the pattern.
No. The server aborts the statement as soon as compilation fails. You must fix the pattern before rerunning the query.