Naveen Chebrolu
Naveen Chebrolu

Reputation: 25

search using regex functionality in SQL

I am searching for a keyword using SQL server and Regex Functionality.

we have a data like leaky gas, leaked gas, and leaking gas.

SELECT [Text field]
FROM [Global database] 
text field is like '%leak[a-z]{1,3} gas%' 

Upvotes: 0

Views: 120

Answers (2)

Gordon Linoff
Gordon Linoff

Reputation: 1270371

SQL Server does not support regular expressions (unless you add your own UDF). It does however extend the LIKE functionality for some basic wildcards.

You can do what you want as:

where field like '%leak[a-z] gas%' or
      field like '%leak[a-z][a-z] gas%' or
      field like '%leak[a-z][a-z][a-z] gas%' 

Upvotes: 1

Related Questions