Troubleshooting Guide: SQL Server Error 573 – Regular Expression Too Complex
Why This Error Happens
Error 573 occurs when SQL Server’s built-in regular expression engine (used internally by functions like LIKE with complex wildcard patterns, or T-SQL regex-based operations) hits an internal complexity threshold while parsing a pattern string. This typically happens with patterns containing excessive nested wildcards, overly long strings, or a high number of alternations that cause the regex evaluator’s internal state machine to exceed its processing limits. It is not a corruption issue but rather a query-design problem where the pattern itself is too complex for the engine to evaluate efficiently within its safety bounds.
Step-by-Step Resolution Guide
Step 1: Identify the Offending Query and Pattern
- Check the SQL Server Error Log (
C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOG) for the full text of the failing statement. - Use SQL Server Profiler or Extended Events to capture the exact query executing at the time of the error.
- Look specifically for
LIKE,PATINDEX, orsys.dm_*calls using long wildcard strings (e.g.,%value1%value2%value3%...).
Step 2: Simplify the Regular Expression Pattern
- Break a single complex pattern into multiple simpler
LIKEconditions joined byAND/ORinstead of one long chained wildcard string. - Replace nested
%...%...%chains withCHARINDEX()orPATINDEX()calls for more predictable performance. - Example rewrite:
-- Instead of:
WHERE column LIKE '%a%b%c%d%e%f%'
-- Use:
WHERE column LIKE '%a%' AND column LIKE '%b%' AND column LIKE '%c%'
Step 3: Increase Query Complexity Tolerance (If Applicable)
- Review and adjust the
MAXRECURSIONand query timeout settings if the pattern is part of a recursive CTE feeding into the LIKE clause. - If using SQL Server 2025’s enhanced regex functions (
REGEXP_LIKE,REGEXP_REPLACE), reduce backtracking-heavy constructs such as nested quantifiers(a+)+. - Apply
OPTION (MAXDOP 1)temporarily to rule out parallel plan interference with pattern evaluation.
Step 4: Update SQL Server Cumulative Updates
- Navigate to
Control Panel > Programs > Programs and Featureson Windows Server 2025 / Windows 11 to confirm the current CU build. - Download and apply the latest Cumulative Update for SQL Server 2025 from the Microsoft Update Catalog, as regex engine limits are periodically tuned in servicing releases.
- Restart the SQL Server service via
services.mscafter installation.
Alternative or Verification Steps
- Re-run the original query after simplification and confirm Error 573 no longer appears in the ERRORLOG or client output.
- As an alternative, offload complex pattern matching to a CLR function or external application layer (e.g., a .NET regex library) instead of relying on native T-SQL wildcard evaluation for very long or deeply nested patterns.