求一个正则 要求匹配所有一个字符串中是否有中文例如  string str1="aaaaaaaa中aaaaaaaa"  不通过
      string str1="aaaaaaaa中aaaaaaaa"  通过
      string str2="<table><tr><td>ldjfl中jgldfgjldjg</td></tr></table>"  不通过
      string str2="<table><tr><td>ldjfl6jgldfgjldjg</td></tr></table>"  通过
      string str3="<table><tr><td style="font:宋体">ldjfl6jgldfgjldjg</td></tr></table>"  通过想表达的就是匹配 每个标签对里面的内容是否全是中文,而标签对里面的中文则不匹配,因为有可能是样式的属性值  求高手帮忙

解决方案 »

  1.   

    "<table>[\s]*<tr>[\s]*<td[\s]*[\S]*>[\s]*[\w]*[\XXXX][\w]*[\s]*</td>[\s]*</tr>[\s]*</table>""td[\s]*[\S]*>[\s]*[\w]*[\XXXX][\w]*[\s]*</td>"XXXX是中文字符 正则给忘记了 自己查查呗 如果以上文字匹配成功则不通过
    不过我还是用正则截取  在用程序判断最好一些
      

  2.   


    这样的话就限定死了标签了TABLE 如果是UL呢,  其实我想要的是不管是什么标签,我只需求判断所有标签对里面的字符有没有中文出现,如果有则不是我想要的,如果所有标签对里面没有任何一个中文则是我想想的,如果只是一个判断所有HTML中是否有中文可能正则网上好找点,但是如果是标签对里面的中文则不匹配,就不太好找了,求高手指点
      

  3.   

    http://topic.csdn.net/u/20110629/12/39894793-c3ce-4eef-b6e1-0901ede03ce6.html?6836using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.IO;
    namespace sxLdfang
    {
        class Program
        {
            static void Main(string[] args)
            {
                string html = @"<table><tr><td style=""font:宋体"">tong guo</td></tr></table>";
                string pattern = @"(?<=(^|>)[^<]*)[\u4e00-\u9fa5]+";
                if(Regex.IsMatch(html, pattern))
                {
                    Console.WriteLine("不通过");
                }
                else
                {
                    Console.WriteLine("通过");
                }
                Console.ReadKey();
            }
        }
    }