我将如何使用 Regex 匹配 Unicode 字符串?我正在从一个文本文件中加载几个关键字,并将它们与 Regex 一起用于另一个文件。关键字都包含 unicode(例如á
,等)。我不确定问题出在哪里。我必须设置一些选项吗?
代码:
foreach (string currWord in _keywordList)
{
MatchCollection mCount = Regex.Matches(
nSearch.InnerHtml, "\\b" + @currWord + "\\b", RegexOptions.IgnoreCase);
if (mCount.Count > 0)
{
wordFound.Add(currWord);
MessageBox.Show(@currWord, mCount.ToString());
}
}
并将关键字读取到列表中:
var rdComp = new StreamReader(opnDiag.FileName);
string compSplit = rdComp.ReadToEnd()
.Replace("\r\n", "\n")
.Replace("\n\r", "\n");
rdComp.Dispose();
string[] compList = compSplit.Split(new[] {'\n'});
然后我将数组更改为列表。