MySQL REGEXP for SQL Server

What is the equivalent SQL Server MySQL expression below?

... WHERE somefield REGEXP '^[[:blank:]]*ASD[[:blank:]]*$|^[[:blank:]]*ASD[[:blank:]]*[[.vertical-line.]]|[[.vertical-line.]][[:blank:]]*ASD[[:blank:]]*$|[[.vertical-line.]][[:blank:]]*ASD[[:blank:]]*[[.vertical-line.]]' 
+6
sql regex mysql sql-server
source share
1 answer

Unfortunately, support for regular expressions in mssql is terrible, the closest like operator, which skips regular expression functionality by a mile. You will need to take a look at breaking up the regular expression into several similar statements and probably do some dirty string manipulations to mimic what you are trying to achieve.

For example, if we could replicate [[: blank:]] on [] (read [Space Tab]), we can’t apply zero or more, so instead we need to deduce them from the expression, but this will match β€œASD” , so we need to check for the presence of ASD in the unchanged string.

I think the following will replace your regex, but it was quickly assembled, so check it carefully.

 replace(replace(somefield,' ',''),' ','') in ('ASD','|ASD','|ASD|','ASD|') and somefield like '%ASD%' 

Again, in my substitution statements, one space with another tab.

+3
source share

All Articles