[英]How to strip all non-alphabetic characters (except hyphen) from string in SQL Server?
Select dbo.[RemoveNonAlphaNumExceptSub]('aAbc123-4def5678ghi90 jkl#^.\')
How to strip all non-alphabetic characters from string in SQL Server? 如何在SQL Server中从字符串中剥离所有非字母字符?
Create Function [dbo].[RemoveNonAlphaNumExceptSub]( @Temp VarChar( max ) )
Returns VarChar( 1000 )
AS
Begin
Declare @KeepValues as varchar( 50 )
Set @KeepValues = '%[^a-z0-9]%'
While PatIndex( @KeepValues, @Temp ) > 0
Set @Temp = Stuff( @Temp, PatIndex( @KeepValues, @Temp ), 1, '' )
Return @Temp
End
Try escaping it by placing a backslash in front of the regex pattern like: '%[^a-z0-9\\-]%'
. 尝试通过在正则表达式模式前面放置反斜杠来转义它,例如: '%[^a-z0-9\\-]%'
。
Alternatively, you can place the hyphen as the first character in the pattern like '%[-^a-z0-9]%'
或者,您可以将连字符作为模式中的第一个字符,例如'%[-^a-z0-9]%'
Feel free to refer to this post for more help , or refer to this post too . 欢迎参阅此帖子以获得更多帮助 ,或也参阅此帖子 。
这最终可以工作'%[^ a-z0-9-]%'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.