|
/// 是否匹配正则表达式 ///
/// 输入的字符串
/// 正则表达式
/// 是否忽略大小写
/// [Microsoft.SqlServer.Server.SqlFunction] 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;
} /// 获取正则表达式分组中的字符 ///
/// 输入的字符串
/// 正则表达式
/// 分组的位置
/// 返回字符的最大长度
/// [Microsoft.SqlServer.Server.SqlFunction] 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[groupId].Value;
strReturn = (strReturn.Length |
|
|