cfsky 发表于 2018-10-14 11:57:58

SQL Server中使用正则表达式

/// 是否匹配正则表达式    ///   
    /// 输入的字符串
  
    /// 正则表达式
  
    /// 是否忽略大小写
  
    ///       public static bool RegexMatch(string input, string pattern, bool ignoreCase)
  
    {      bool isMatch = false;      if (!string.IsNullOrEmpty(input) && !string.IsNullOrEmpty(pattern))
  
      {            try
  
            {
  
                Match match = null;                if (ignoreCase)
  
                  match = Regex.Match(input, pattern, RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Compiled);                else
  
                  match = Regex.Match(input, pattern, RegexOptions.Multiline | RegexOptions.Compiled);                if (match.Success)
  
                  isMatch = true;
  
            }            catch { }
  
      }      return isMatch;
  
    }    /// 获取正则表达式分组中的字符    ///
  
    /// 输入的字符串
  
    /// 正则表达式
  
    /// 分组的位置
  
    /// 返回字符的最大长度
  
    ///       public static string GetRegexMatchGroups(string input, string pattern, int groupId, int maxReturnLength)
  
    {      string strReturn = string.Empty;      if (!string.IsNullOrEmpty(input) && !string.IsNullOrEmpty(pattern))
  
      {            try
  
            {
  
                Match match = Regex.Match(input, pattern, RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Compiled);                if (match.Success && (groupId < match.Groups.Count))
  
                {
  
                  strReturn = match.Groups.Value;
  
                  strReturn = (strReturn.Length
页: [1]
查看完整版本: SQL Server中使用正则表达式