我正在尝试使用Regex.Match方法在文件中查找匹配的字符。目前,正则表达式匹配方法使用内存中文件的行(strLine)并根据指定的(m_strRegEx)和任何适用的选项进行检查。虽然我怎么能从这里输出数学字符?
Match mtch;
if (m_bIgnoreCase == true)
mtch = Regex.Match(strLine, m_strRegEx, RegexOptions.IgnoreCase);
else
mtch = Regex.Match(strLine, m_strRegEx);
答案 0 :(得分:1)
我想你需要以下内容:
Match mtch = Regex.Match(strLine, m_strRegEx, m_bIgnoreCase ? RegexOptions.IgnoreCase : RegexOptions.None);
if (mtch.Success)
{
Console.WriteLine(mtch.Value);
}
或者您可以一次性搜索strLine中的所有事件:
MatchCollection matches = Regex.Matches(strLine, m_strRegEx, m_bIgnoreCase ? RegexOptions.IgnoreCase : RegexOptions.None);
foreach (var match in matches)
{
Console.WriteLine(match.ToString());
}