public class RegexHelper
{
///
/// 验证输入字符串是否与模式字符串匹配,匹配返回true
///
/// 输入字符串
/// 模式字符串
public static bool IsMatch(string input, string pattern)
{
return IsMatch(input, pattern, RegexOptions.IgnoreCase);
}
///
/// 验证输入字符串是否与模式字符串匹配,匹配返回true
///
/// 输入的字符串
/// 模式字符串
/// 筛选条件
public static bool IsMatch(string input, string pattern, RegexOptions options)
{
return Regex.IsMatch(input, pattern, options);
}
///
/// 搜索匹配的值
///
///
///
///
public MatchCollection Matches(string str, string pattern)
{
Regex reg = new Regex(pattern, RegexOptions.IgnoreCase); // 搜索匹配的字符串
var list = reg.Matches(str);
return list;
}
///
/// 正在表达式 拆分字符串
///
///
///
///
public string[] Split(string str, string pattern)
{
var items = Regex.Split(str, pattern);
return items;
}
///
/// 正则替换字符串
///
/// 要搜索匹配项的字符串
/// 要匹配的正则表达式模式
/// 替换字符串
///
public string Replace(string input, string pattern, string replacement)
{
var str = Regex.Replace(input, pattern, replacement);
return str;
}
}