/// <summary>
/// 获取一个目标的匹配结果
/// </summary>
/// <param name="input">要匹配的字符串</param>
/// <param name="pattern"></param>
/// <param name="find"></param>
/// <returns></returns>
public static Match GetMatch(string input, string pattern, string find)
{
string _pattn = Regex.Escape(pattern);
_pattn = _pattn.Replace(@"\[变量]", @"[\s\S]*?");
_pattn = Regex.Replace(_pattn, @"((\\r\\n)|(\\ ))+", @"\s*", RegexOptions.Compiled);
if (Regex.Match(pattern.TrimEnd(), Regex.Escape(find) + "$", RegexOptions.Compiled).Success)
_pattn = _pattn.Replace(@"\" + find, @"(?<TARGET>[\s\S]+)");
else
_pattn = _pattn.Replace(@"\" + find, @"(?<TARGET>[\s\S]+?)");
Regex r = new Regex(_pattn, RegexOptions.IgnoreCase | RegexOptions.Compiled);
Match m = r.Match(input);
return m;
}
通过正则表达式,匹配字符串
你自己写的不清楚?全是正则表达式,你要看懂肯定得需要你自己熟悉这些正则表达式的符号。
Regex就是正则