<h1>广汽本田 2005年产 雅阁2.0-AT标准型(国Ⅲ) 200503年款</h1>
用正则表达式提取出"广汽本田","2005","雅阁","2.0","AT","200503","雅阁2.0-AT标准型(国Ⅲ)"
格式并不统一,有一些是这样子的.如下<h1>大众 2009年产 甲壳虫-1.8T-A/MT 敞篷版 200601年款</h1>这个就要提取出"大众","2009","甲壳虫","1.8","A/MT","200601".品牌,生产年份.款式年份这些格式是固定的,变速方式也就是"AT A/MT"这些主要有5个,"AT MT A/MT CVT CVT/MT",可以匹配这五项.可能有些复杂.希望能够正确地提取出品牌,生产年份.款式年份和变速方式.其它的尽量能够提取出来就行了.

解决方案 »

  1.   

    <h1>广汽本田 2005年产 雅阁2.0-AT标准型(国Ⅲ) 200503年款 </h1> 那就只取"广汽本田","2005","雅阁2.0-AT标准型(国Ⅲ)","200503" 这样呢?
      

  2.   

    首先使用字符串Split方法以空格为间隔字符,将其分解品牌,直接可得到
    生产年份,Replace掉“年产”两个字符
    款式年份,Replace掉“年款”两个字符
    车系、排量、变速方式,可以用这个正则表达式来解析:
    @"([\u4e00-\u9fa5]+)([0-9.]+)-((AT)|(MT)|(A/MT)|(CVT)|(CVT/MT))"
      

  3.   

    正则 表达式 不太会  呵呵
     C# 我给你写出来了
     string ass = "<h1>广汽本田 2005年产 雅阁2.0-AT标准型(国Ⅲ) 200503年款 </h1>";
                string[] arr = ass.Split('<');
                string tempa = "";
                string temp = "";
                string tem = "";
                string te = "";
                foreach (string ch in arr)
                {
                    tempa += ch;
                }
                string[] brr = tempa.Split('h1');
                foreach(string bh in brr)
                {
                    temp += bh;
                }
                string[] crr = temp.Split('>');
                foreach (string ch in crr)
                {
                    tem += ch;
                }
                string[] drr = tem.Split('/');
                foreach(string dh in drr)
                {
                    te += dh;
                }
                TextBox1.Text = te;//效果是  大众 2009年产 甲壳虫-1.8T-A/MT 敞篷版 200601年款不知道是lz 想要的效果么·
      

  4.   

    \<h1\>([^\s]*)\s(\d{4})\S*\s\D*([\d\.]*)\D*(\d*)四个括号里取到的分别是你要的值var t = "<h1>广汽本田 2005年产 雅阁2.0-AT标准型(国Ⅲ) 200503年款 </h1> ";
    var value = t.match(/\<h1\>([^\s]*)\s(\d*)\S*\s\D*([\d\.]*)\D*(\d*)/i);WScript.Echo(value[1]);
    WScript.Echo(value[2]);
    WScript.Echo(value[3]);
    WScript.Echo(value[4]);
      

  5.   


    一次性取出和分别取有分别吗?            Regex reg = new Regex(@"(?i)<h1>(?<com>[^  ]+)[  ]+(?<year>\d{4})年产[  ]+(?<pro>[^-\d]+)-?(?<typ>[\d.]+)T?-(?<exh>[ATMT/CV ]+)[^  ]+[  ]+(?<tim>\d{6})年款[  ]*</h1>");
                MatchCollection mc = reg.Matches(yourStr);
                foreach (Match m in mc)
                {
                    richTextBox2.Text += m.Groups["com"].Value + "\n";
                    richTextBox2.Text += m.Groups["year"].Value + "\n";
                    richTextBox2.Text += m.Groups["pro"].Value + "\n";
                    richTextBox2.Text += m.Groups["typ"].Value + "\n";
                    richTextBox2.Text += m.Groups["exh"].Value + "\n";
                    richTextBox2.Text += m.Groups["tim"].Value + "\n\n";
                }
      

  6.   

    在.NET中当然是可以的,因为\s在.NET中是可以匹配全角空格的,我在调试工具名写的,所以写成那种形式了,其实也无所谓了Regex reg = new Regex(@"(?i)<h1>(?<com>\S+)\s+(?<year>\d{4})年产\s+(?<pro>[^-\d]+)-?(?<typ>[\d.]+)T?-(?<exh>[ATMT/CV ]+)\S+\s+(?<tim>\d{6})年款\s*</h1>");
      

  7.   

    全角和半角是很据什么分的?
    [^\uFF00-\uFFFF] 
      

  8.   

     Regex reg = new Regex(@"(?i)<h1>(?<com>[^  ]+)[  ]+(?<year>\d{4})年产[  ]+(?<pro>[^-\d]+)-?(?<typ>[\d.]+)T?-(?<exh>[ATMT/CV ]+)[^  ]+[  ]+(?<tim>\d{6})年款[  ]*</h1>");
                MatchCollection mc = reg.Matches(yourStr);
                foreach (Match m in mc)
                {
                    richTextBox2.Text += m.Groups["com"].Value + "\n";
                    richTextBox2.Text += m.Groups["year"].Value + "\n";
                    richTextBox2.Text += m.Groups["pro"].Value + "\n";
                    richTextBox2.Text += m.Groups["typ"].Value + "\n";
                    richTextBox2.Text += m.Groups["exh"].Value + "\n";
                    richTextBox2.Text += m.Groups["tim"].Value + "\n\n";
                }
    这代码中的(?i)是什么意思呀?>[^  ]+)[  ]+这是空与非空的意思吗?