SQL Server 2025: REGEXP_LIKE() – Native Regular Expressions Arrive**
Introduction
SQL Server has never had true regular expression support built into the engine. Developers relied on:
• CLR functions
• LIKE hacks
• CHARINDEX
• XML PATH tricks
• External tools
That changes in SQL Server 2025 with the introduction of REGEXP_LIKE(), the first native RegEx function. It finally gives SQL Server the pattern-matching power found in Oracle, PostgreSQL, and MySQL.
Today we’ll look at how REGEXP_LIKE works, where it shines, how the optimizer handles it, and the exact patterns that SQL Server supports.
This is the foundation for the entire RegEx feature family coming in Days 7, 8, and 9.
What REGEXP_LIKE() Does
REGEXP_LIKE() checks whether a string matches a given regular expression pattern. It returns:
• 1 → match
• 0 → no match
Basic syntax:
REGEXP_LIKE(expression, pattern)
Example:
SELECT REGEXP_LIKE('Valhallan', 'hall') AS MatchResult;
Returns:
1
Supported Pattern Types
SQL Server 2025 uses a modern, Perl-compatible RegEx engine with support for:
• Literal matches
• Character classes: [a-z], [0-9]
• Anchors: ^, $
• Quantifiers: +, *, ?, {n}, {n,}
• Groups: (...)
• Alternation: a|b
• Escaped characters: \s, \d, \w, and more
Example: Match a gamer tag that ends with digits.
SELECT REGEXP_LIKE('Luke123', '^[A-Za-z]+[0-9]+$');
Case Sensitivity
RegEx is case sensitive unless you specify the i flag.
SELECT REGEXP_LIKE('VALHALLAN', 'valhallan', 'i');
Supported flags:
• i case-insensitive
• m multi-line
• s single-line
• x ignore whitespace
Example with flags:
SELECT REGEXP_LIKE('ValHallan', '^valh', 'i');
Advanced Examples
Here are real patterns you can use immediately.
1. Validate email format
SELECT *
FROM Users
WHERE REGEXP_LIKE(Email, ‘^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,}$’);
2. Detect numeric-only gamer IDs
SELECT REGEXP_LIKE('5021', '^\d+$');
3. Validate a Fortnite player tag
Letters, digits, underscores:
SELECT REGEXP_LIKE('ProBuilder_21', '^[A-Za-z0-9_]+$');
4. Detect toxic messages
SELECT *FROM ChatLogWHERE REGEXP_LIKE(Message, '(idiot|trash|ez|noob)');
Great for moderation dashboards.
5. Extract meaningful log events
Find entries starting with timestamp format:
SELECT *FROM LogsWHERE REGEXP_LIKE(EventText, '^\d{4}-\d{2}-\d{2}');
Performance and Optimization
REGEXP_LIKE is a scalar function. It is not SARGable, so SQL Server cannot perform index seeks against it.
However, SQL Server 2025 optimizes RegEx evaluation internally:
• Compiled pattern cache
• Fast failure paths
• SIMD instructions for simple character classes
• Safe fallback to CPU-only regex engine
Best performance practices:
1. Use anchors
^pattern$ is much faster than pattern.
2. Avoid wide NVARCHAR(MAX) columns
Use VARCHAR(200–2000) when possible.
3. Pre-filter with LIKE
WHERE SomeColumn LIKE '%@%' AND REGEXP_LIKE(SomeColumn, '@[A-Za-z0-9.-]+\.');
4. Avoid unnecessary flags
Flags increase processing overhead.
Migration from Older RegEx Workarounds
Before SQL Server 2025, people used:
• LIKE '%pattern%' – not accurate
• PATINDEX – limited
• CLR Regex – required permissions
• External scripts in Python or PowerShell
Now you simply write:
REGEXP_LIKE(ColumnName, 'pattern')
Cleaner, faster, safer.
Common Mistakes
1. Misusing escape characters
Remember to double-escape in T-SQL:
SELECT REGEXP_LIKE('123', '\\d+');
2. Not using anchors
Example mistake:
REGEXP_LIKE('abc123', '\d')
This returns 1.
If you want only digits:
REGEXP_LIKE('abc123', '^\\d+$')
3. Using RegEx when LIKE is enough
If you only need simple wildcard matching, stick to LIKE.
Workshop: REGEXP_LIKE Playground
Step 1. Create test data
CREATE TABLE TestPatterns2025 ( Id INT IDENTITY, Value VARCHAR(200));INSERT INTO TestPatterns2025 (Value)VALUES ('Luke123'), ('Pro_Editor'), ('Noob!'), ('Champion'), ('VALHALLAN2025');
Step 2. Match values ending with digits
SELECT *FROM TestPatterns2025WHERE REGEXP_LIKE(Value, '^[A-Za-z]+[0-9]+$');
Step 3. Match uppercase only
SELECT *FROM TestPatterns2025WHERE REGEXP_LIKE(Value, '^[A-Z]+$');
Step 4. Detect non-allowed characters
SELECT *FROM TestPatterns2025WHERE REGEXP_LIKE(Value, '[^A-Za-z0-9_]');
Step 5. Case-insensitive matching
SELECT *FROM TestPatterns2025WHERE REGEXP_LIKE(Value, '^val', 'i');
Step 6. Build a moderation filter
SELECT *FROM TestPatterns2025WHERE REGEXP_LIKE(Value, '(noob|trash|ez)', 'i');
Final Thoughts
REGEXP_LIKE is the gateway to full pattern matching in SQL Server. It replaces years of workarounds and gives developers an engine-level tool that pairs perfectly with API calls, JSON, and text-heavy workloads. In tomorrow’s article, Day 7, we expand this foundation with REGEXP_SUBSTR() and REGEXP_REPLACE(), which unlock substring extraction and transformation directly inside SQL.
References
• REGEXP_LIKE
https://learn.microsoft.com/sql/t-sql/functions/regexp-like-transact-sql
• Regular Expression Syntax
https://learn.microsoft.com/sql/t-sql/functions/regular-expression-reference
• SQL Server 2025 New Features
https://learn.microsoft.com/sql/sql-server/what-s-new-in-sql-server-2025
Discover more from SQLYARD
Subscribe to get the latest posts sent to your email.


