0

What would be the proper format for the following regular expression in SQL Server?

select top 100 * 
from posts
where tags like '(c++)|(performance)'

1 Answer 1

2

SQL Server does not support formal regex, so you will have to use LIKE here:

SELECT TOP 100 *
FROM posts
WHERE tags LIKE '%c++%' OR tags LIKE '%performance%';

Note: If the tags column really stores one tag per record, then just use equality checks:

SELECT TOP 100 *
FROM posts
WHERE tags IN ('%c++', 'performance');
Sign up to request clarification or add additional context in comments.

2 Comments

ah that's so strange, for everything else that it does support, to think of something so basic...
@samuelbrody1249 SQL Server's LIKE operator is enhanced and does have some very basic regex capability, and there is a PATINDEX function with some regex support. If you show your actual data, maybe the above query can be improved upon.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.