T-SQL 正则表达式匹配"One or More"运算符



在MS SQL中,是否存在允许匹配一个或多个字符的运算符?(我很好奇它是否在T-SQL中明确实现——其他解决方案当然也是可能的,我在下面的问题示例中使用了其中一个…(

我知道在SQL中,这可以通过通配符/类方法显式地实现,并获得不同程度的成功:

SELECT *
FROM table
-- finds letters aix and then anything following it
WHERE column LIKE 'aix_x%'

在Python中,"+"运算符允许这样做:

import re
str = "The rain in Spain falls mainly in the plain!"
#Check if the string contains "ai" followed by 1 or more "x" characters:
# finds 'ai' + one or more letters x
x = re.findall("aix+", str)
print(x)
if (x):
print("Yes, there is at least one match!")
else:
print("No match")

检查字符串是否包含后跟1个或多个"x"字符的"ai":查找"ai"+一个或多个字母x

如果这是你想要的,那么:

其中str类似于"%AX%">

做你想做的事。

如果需要下划线,则下划线是LIKE表达式中的通配符。SQL Server中最简单的方法可能是使用字符类:

其中str类似于'%ai[_]x%'

另一种解决方案是:

其中str-like"%ai$_x%"转义"$">

相关内容

最新更新