Sql Like to RegEx Sql Like to RegEx sql-server sql-server

Sql Like to RegEx


It is possible to add Regular Expression parsing to SQL server, using a CLR function. This is possible from SQL 2005 and up. See here for a great example.


I'd imagine

SELECT ...FROM [Table]WHERE col LIKE 'country=[A-Za-z0-9]%&sessionid=[A-Za-z0-9]%'

might be close enough? If the aim is just to bring back records with non blank country and sessionid values.

If the value in the column wouldn't necessarily start with 'country' you'd have to use WHERE col LIKE '%country=[A-Za-z0-9]%&sessionid=[A-Za-z0-9]%' which could slow things down considerably as per KM's answer.


Check this function of sql. It may help you to achieve your task : PATINDEX('%[^0-9\.]%',@Input)

PATINDEX (Transact-SQL)