1

I am trying to run a regular expression in a SQL statement to return all rows where the regex is true.

This is the regex:

(A1|A2|A3|A4).{0,50}(B1|B2|B3).{0,200}(word1|word2)

I have tried this (and variants of):

SELECT * FROM TABLE_NAME WHERE COLUMN_NAME LIKE  '%[(A1|A2|A3|A4).{0,50}(B1|B2|B3).{0,200}(word1|word2)]%'

The regex itself is okay, but running seems to be the problem. Any help is appreciated.

Thom A
  • 88,727
  • 11
  • 45
  • 75
user1624577
  • 547
  • 2
  • 6
  • 15
  • share sample data and its expected ouput – Zaynul Abadin Tuhin Jul 17 '18 at 15:35
  • 3
    SQL Server doesn't support Regex. You have the `LIKE` expression ([LIKE (Transact-SQL)](https://learn.microsoft.com/en-us/sql/t-sql/language-elements/like-transact-sql?view=sql-server-2017)), however, this does **not** have same functionality as Regex; it just uses "Regex like" syntax. – Thom A Jul 17 '18 at 15:36
  • As @Larnu stated, SQL Server doesn't natively support Regex, however it does provide [PATINDEX](https://learn.microsoft.com/en-us/sql/t-sql/functions/patindex-transact-sql?view=sql-server-2017) which you *might* be able to bend to your will and achieve similar results. – Diado Jul 17 '18 at 15:40

0 Answers0