就像正则表达式没有给出正确的结果 [英] Like with Regular Expression not giving proper result

查看:68
本文介绍了就像正则表达式没有给出正确的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

declare @test varchar(50)
set @test='sad@fd'
if @test LIKE '%[a-zA-Z0-9  ./,()?''+-]%'
print 'yes'
else
print 'no'



我的上述代码给出是的结果,因为它应该给不,因为我不允许在正则表达式中使用'@'。是否有任何错误。

我的要求是允许字母数字字符串./,()?'+ - 如果字符串包含,则允许使用此字符。


My above code giving yes result as it should give no as i am not allowing '@' in regular expression.Is there anything wrong.
My requirement is allow alpha numeric string with "./,()?''+-" this character allowed if string contains.

推荐答案

LIKE不支持正则表达式。如果你想要超越LIKE支持的范围(这并不多),你需要使用全文索引。在任何情况下,使用全文允许SQL构建索引,LIKE会丢弃索引的使用并减慢查询速度。



您的其他选项,如果您需要正则表达式支持,就是使用CLR支持编写一个使用正则表达式的.NET方法。



阅读文档通常很好,而不是制作文件并希望它们将起作用: - )
LIKE does not support regular expressions. You need to use the full text index if you want to go beyond what LIKE supports ( which is not much ). In any case, using Full Text allows SQL to build an index, LIKE discards the use of indexes and slows down your queries.

Your other option, if you need regex support, is to use the CLR support to write a .NET method that uses regex.

It is generally good to read the documentation instead of making things up and hoping they will work :-)


参考: MS SQL Server 2005/2008中的正则表达式 [ ^ ]


这篇关于就像正则表达式没有给出正确的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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