在SQL Server存储过程中使用RegEx

时间:2012-01-19 05:58:39

标签: sql-server regex tsql

这是VB Script中的代码,如果我要在SQL Server中构建一个名为dbo.FileNameEncode(str)的函数,该怎么做呢?

Function FileNameEncode(ByVal strFileName)     
    Dim oReg     
    strFileName = LTrim(Rtrim(strFileName))
    Set oReg = New RegExp     
    oReg.IgnoreCase = True     
    oReg.Global = True     
    oReg.Pattern = "[^a-z\d\s.]+"     
    FileNameEncode = Replace(oReg.Replace(strFileName, ""), " ", "_")     
    Set oReg = Nothing 
End Function 

1 个答案:

答案 0 :(得分:2)