-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Expand file tree
/
Copy pathRegEx.cs
More file actions
46 lines (40 loc) · 1.49 KB
/
RegEx.cs
File metadata and controls
46 lines (40 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using Microsoft.SqlServer.Server;
using System.Text.RegularExpressions;
/// <summary>
/// https://blogs.msdn.microsoft.com/sqlclr/2005/06/29/working-with-regular-expressions/
/// </summary>
public partial class RegEx
{
[SqlFunction(IsDeterministic = true, IsPrecise = true)]
public static bool Match(string source, string pattern)
{
Regex r1 = new Regex(pattern);
return r1.Match(source).Success;
}
[SqlFunction(IsDeterministic = true, IsPrecise = true)]
public static bool CompiledMatch(string source, string pattern)
{
return Regex.Match(source, pattern, RegexOptions.Compiled).Success;
}
[SqlFunction(IsDeterministic = true, IsPrecise = true)]
public static string Substring(string source, string pattern)
{
Regex r1 = new Regex(pattern);
return r1.Match(source).Value;
}
[SqlFunction(IsDeterministic = true, IsPrecise = true)]
public static string CompiledSubstring(string source, string pattern)
{
return Regex.Match(source, pattern, RegexOptions.Compiled).Value;
}
[SqlFunction(IsDeterministic = true, IsPrecise = true)]
public static string Replace(string source, string pattern, string value)
{
return Regex.Replace(source, pattern, value);
}
[SqlFunction(IsDeterministic = true, IsPrecise = true)]
public static string CompiledReplace(string source, string pattern, string value)
{
return Regex.Replace(source, pattern, value, RegexOptions.Compiled);
}
};