如何使用Regex來匹配Unicode字符串?我從文本文件中加載了幾個關鍵字,並在另一個文件中將它們與正則表達式一起使用。這兩個關鍵字都包含unicode(如á
等)。我不確定問題出在哪裏。有我需要設置的選項嗎?正則表達式不匹配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'});
然後我將陣列更改列表。
您可以發佈您的代碼,是一個使用正則表達式的片段?這可能是一個字符集問題(例如,與正則表達式無關),或正則表達式問題,或... – 2010-03-29 13:33:22
你使用什麼樣的正則表達式?請顯示一些代碼。 – 2010-03-29 13:33:38
關鍵字是否始終以單詞字符(即字母,數字或下劃線)開頭和結尾? – 2010-03-29 15:08:17