复制代码 代码如下:
/// <summary>
/// Regs the ex match.
/// </summary>
/// <param>The input value.</param>
/// <param>The regex pattern.</param>
/// <remarks>Author: Petter Liu </remarks>
/// <returns>1 match,0 not match</returns>
[SqlFunction]
public static bool RegExMatch(string inputValue, string regexPattern)
{
// Any nulls - we can't match, return false
if (string.IsNullOrEmpty(inputValue) || string.IsNullOrEmpty(regexPattern))
return false;
Regex r1 = new Regex(regexPattern.TrimEnd(null));
return r1.Match(inputValue.TrimEnd(null)).Success;
}
复制代码 代码如下:
CREATE ASSEMBLY [RegExCLR] FROM 'RegExCLR.dll';
-- Add the REGEX function. We want a friendly name
-- RegExMatch rather than the full namespace name.
-- Note the way we have to specify the Assembly.Namespace.Class.Function
-- NOTE the RegExCLR.RegExCLR
-- (one is the assembly the other is the namespace)
CREATE FUNCTION RegExMatch ( @inputCalue NVARCHAR(4000),
@regexPattern NVARCHAR(4000) ) RETURNS BIT
AS EXTERNAL NAME RegExCLR.RegExCLR.ClrClass.RegExMatch;
新闻热点
疑难解答