MySQL REGEXP到SQL Server [英] MySQL REGEXP to SQL Server

查看:60
本文介绍了MySQL REGEXP到SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与下面的MySQL表达式等效的SQL Server是什么?

What is the SQL Server equivalent of the 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.]]'

推荐答案

不幸的是,mssql中对regex的支持令人恐惧,最接近的运算符"like",使regex的功能大大漏了.您将不得不考虑将正则表达式分解为多个类似的语句,并可能进行一些肮脏的字符串操作以模仿您要实现的目标.

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.

例如,虽然我们可以用[]复制[[:blank:]](请阅读[空格键]),但是我们不能强制匹配零个或多个它们,因此我们不得不将它们从表达式中剥离出来,但这会匹配"ASD",因此我们需要测试未修改的字符串中是否存在ASD.

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 ' A S D ' 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.

这篇关于MySQL REGEXP到SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆