正则表达式不匹配的Unicode [英] Regex Not Matching Unicode

查看:354
本文介绍了正则表达式不匹配的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆