IIS://localhost/w3svc/1/root/1/2/3
我要得到w3svc与root中间的数字,怎么写正则表达式,这个数字可能是任何数字,只要这个数字。

解决方案 »

  1.   

    参考http://bingning.net/VB/SOURCE/string/regexmatch.html这里看看
      

  2.   


    declare @x nvarchar(100),@l int, @l2 int,@num varchar(200)
    set @x = 'IIS://localhost/w3svc/1/root/1/2/3'
    set @l = Charindex('w3svc/',@x)
    set @l2 = Charindex('/root/',@x)
    set @num = substring(@x,@l+6,@l2-@l-6)
    print(@num)
    这个是我用sql写的思路
    你看看
    一般找出数字 前头的位置,然后找出数字后头的位置,想减得出数字长度,
    然后截取字段。
    正则也没有办法获得你想要的。只能做个判断
      

  3.   

    string output=string.Empty;
    Regex reg=new Regex(@"iis://localhost/w3svc/(\d+)/root",RegexOption.IgnoreCase);
    if(reg.IsMatch(XXXX))
    {
      output=reg.Matches(XXXX)[1];
    }
      

  4.   

    @"(?i)(?<=IIS://localhost/w3svc/)\d+"
      

  5.   

    string test = "IIS://localhost/w3svc/1/root/1/2/3 ";
    Console.WriteLine("the string is:{0}",test);Match m = Regex.Match(test, @"(?<=w3svc/).+(?=/root.+)", RegexOptions.IgnoreCase);
    Console.WriteLine("match is:{0}",m.Value);            
    /*
    the string is:IIS://localhost/w3svc/1/root/1/2/3
    match is:1
    请按任意键继续. . .
    */
      

  6.   


    string str = "IIS://localhost/w3svc/1/root/1/2/3";
    string result = Regex.Match(str,@"/w3svc/(\d+)/root/").Groups[1].Value;