MatchCollection mc1 = Regex.Matches(text, @"&#([\d]{5})", RegexOptions.Compiled | RegexOptions.IgnoreCase);
mc2 = Regex.Matches(text, @"\\u([\w]{2})([\w]{2})", RegexOptions.Compiled | RegexOptions.IgnoreCase);
以上两名正则表达式的含义分别是
------解决思路----------------------
// 匹配这样的字符串: &#加5个数字
// 此处 RegexOptions.IgnoreCase 纯属画蛇添足
MatchCollection mc1 = Regex.Matches(text, @"&#([\d]{5})", RegexOptions.Compiled
------解决思路----------------------
RegexOptions.IgnoreCase);
// 匹配这样的字符串: \u加4位汉字或字母或数字或下划线
mc2 = Regex.Matches(text, @"\\u([\w]{2})([\w]{2})", RegexOptions.Compiled
------解决思路----------------------
RegexOptions.IgnoreCase);
------解决思路----------------------
&#([\d]{5}) 匹配&#后面5位数字,个人认为在匹配字符的HTML实体形式
\\u([\w]{2})([\w]{2}) 匹配 \u后面4位字母或者数字或者下划线,个人感觉在匹配 utf-8 与unicode编码。
Compiled 多花些时间优化正则表达式,编译到dll里,占用多点内存,但是匹配更快
IgnoreCase 忽略大小写