我想用正则表达式作验证
http://www.sg.com.cn/12312/123/aa.html  (http://www.sg.com.cn/5位数字/3位数字/2位字符.html我写的正则表达式为
http://www.sg.com.cn/(\d{5}$)/(\d{3}$)/[:alpha:].html新手。刚刚用这个

解决方案 »

  1.   

    Regex reg=new Regex("http://www[\.]sg[\.]com[\.]cn/([\d]{5})/([\d]{3})/([^\.]+?html)");
      

  2.   

    string regexStr = "http://www.sg.com.cn/\\d{5}/\\d{3}/\\S{2}.html";
      

  3.   

    sorry
    string strRegex = "http://www\\.sg\\.com\\.cn/\\d{5}/\\d{3}/\\S{2}.html";
      

  4.   

    我汗~~~~~~~~~
    这个
    string regexStr = "http://www\\.sg\\.com\\.cn/\\d{5}/\\d{3}/\\S{2}\\.html";
      

  5.   

    Regex reg=new Regex(@"http://www[\.]sg[\.]com[\.]cn/([\d]{5})/([\d]{3})/([^\.]+?html)");
    漏了@ 

      

  6.   

    不对呀。。我这样写的
    string a=@"http://www[\.]sg[\.]com[\.]cn/([\d]{5})/([\d]{3})/([^\.]+?html)";
    string b=@"http://www.sg.com.cn/12345/123/ss.html";
    MatchCollection mc;
    try
    {
    mc = Regex.Matches(b,a);
    MessageBox.Show("搜索数目为"+mc.Count,"测试",MessageBoxButtons.OK,MessageBoxIcon.Information); }
    catch
    {
    MessageBox.Show("正则表达式语法错误","测试失败",MessageBoxButtons.OK,MessageBoxIcon.Information);
    }找到数目为0
      

  7.   

    (http://www.sg.com.cn/[\d]{5}/[\d]{3}/[\S]{2}.html)
      

  8.   

    还是不对呀。。稍微变换点击不对了
    tContent.action?id=[\d]{5}/[\d]{3}/[\S]{2}.html验证tContent.action?id=54321/321/ab.html