简体   繁体   中英

MySQL REGEXP to SQL Server

以下MySQL表达式的SQL Server等价物是什么?

... WHERE somefield REGEXP '^[[:blank:]]*ASD[[:blank:]]*$|^[[:blank:]]*ASD[[:blank:]]*[[.vertical-line.]]|[[.vertical-line.]][[:blank:]]*ASD[[:blank:]]*$|[[.vertical-line.]][[:blank:]]*ASD[[:blank:]]*[[.vertical-line.]]'

Unfortunately the regex support in mssql is dreadful, the closest operator is "like" which misses out on the functionality of regex's by a mile. You would have to look at breaking the regex up into multiple like statements and probably doing some dirty string manipulation to emulate what you are attempting to achieve.

For example while we could replicate the [[:blank:]] with [ ] (read [ Space Tab ]) we cant force matching zero or more of them, so instead we have to strip them out of the expression but this would match ' ASD ' so we need to test for the presence of ASD in the unmodified string.

I think the following would replace your regex but it was thrown together quickly so test it carefully.

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

Again in my replace statements one is a space the other a tab.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM