正则表达式不匹配的Unicode [英] Regex Not Matching Unicode
问题描述
我怎么会去使用正则表达式匹配Unicode字符串?我加载在从文本文件一对夫妇的关键字,并使用它们与正则表达式的另一个文件。关键字既包含Unicode(如 A
等)。我不知道问题出在哪里。 ?有一些选项我必须设置
How would I go about using Regex to match Unicode strings? I'm loading in a couple keywords from a text file and using them with Regex on another file. The keywords both contain unicode (such as á
, etc). I'm not sure where the problem is. Is there some option I have to set?
代码:
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'});
然后我改变了数组列表。
Then I change the array to a list.
推荐答案
在一个特定的字符匹配,相信正则表达式的ASCII字符集唯一支持文字。除此之外,你可以使用\uxxxx相匹配,对Unicode代码点。
When matching on a specific character, I believe regular expressions only support literals for the ASCII character set. Beyond that, you can use \uxxxx to match on the Unicode code point.
请参阅的这里。
这篇关于正则表达式不匹配的Unicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!