如何批配以下形式http://www.abc.com/12345
http://www.abc.com/12345/就是批配域名http://www.abc.com/后5个数字再后面有一个或没有/的正则

解决方案 »

  1.   

    不用正则也可以啊
     if (s.EndsWith("/"))//是否有/符号
    {
     
    }
    else
    {
     
    }
      

  2.   

    @"http://www.abc.com/\d{5}/?"  
      

  3.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;namespace ConsoleApplication1
    {
        class Test
        {
            static void Main()
            {
                string[] str = new string[] { @"http://www.abc.com/12345", @"http://www.abc.com/12345/", @"http://www.abc.com/123454" };
                Regex re = new Regex(@"^http://www.abc.com/\d{5}/?$");
                foreach (string s in str)
                {
                    if (re.Match(s).Success)
                        Console.WriteLine(re.Match(s).Value);            }        }
        }
    }
      

  4.   

    是项目规定吗?如果是这样,那就用正则吧
    否则不用正则也完全可以 string[] s = new string[] { "http://www.abc.com/12345/", "http://www.abc.com/12345" };
                foreach (string p in s)
                {
                    if (p.EndsWith("/"))
                         {
                             Console.WriteLine(p);
                          }
                }
      

  5.   

    楼主是在哪里配置urlrewrite的?一般是通过类似下面这种方式进行urlrewrite的<RewriterRule> 
    <LookFor>~/(\d{5})/</LookFor> 
    <SendTo>~/index.aspx?page=$1</SendTo> 
    </RewriterRule>