原文:https://www.jianshu.com/p/ff16a7da6de0

1、vs添加类库,编写如下代码,生成dll

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Text.RegularExpressions;
 6 using System.Threading.Tasks;
 7 
 8 namespace MSSQLRegexExtend
 9 {
10     public class RegexExtend
11     {
12         /// <summary>
13         /// 正则匹配
14         /// </summary>
15         /// <param name="regex">正则表达式</param>
16         /// <param name="input">文本</param>
17         /// <returns></returns>
18         [Microsoft.SqlServer.Server.SqlFunction]
19         public static string Match(string regex, string input)
20         {
21             return string.IsNullOrEmpty(input) ? "" : new Regex(regex, RegexOptions.IgnoreCase).Match(input).Value;
22         }
23 
24         /// <summary>
25         /// 正则替换
26         /// </summary>
27         /// <param name="regex">正则表达式</param>
28         /// <param name="input">文本</param>
29         /// <param name="replace">要替换的目标</param>
30         /// <returns></returns>
31         [Microsoft.SqlServer.Server.SqlFunction]
32         public static string Replace(string regex, string input, string replace)
33         {
34             return string.IsNullOrEmpty(input) ? "" : new Regex(regex, RegexOptions.IgnoreCase).Replace(input, replace);
35         }
36 
37         /// <summary>
38         /// 正则校验
39         /// </summary>
40         /// <param name="regex">正则表达式</param>
41         /// <param name="input">文本</param>
42         /// <returns></returns>
43         [Microsoft.SqlServer.Server.SqlFunction]
44         public static bool IsMatch(string regex, string input)
45         {
46             return !string.IsNullOrEmpty(input) && new Regex(regex, RegexOptions.IgnoreCase).IsMatch(input);
47         }
48     }
49 }
View Code

相关文章:

  • 2021-09-23
  • 2021-07-27
猜你喜欢
  • 2021-10-19
  • 2021-07-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-22
  • 2021-11-10
相关资源
相似解决方案