/template/cn/company.html
/template/en/company.html这样的路径里面取company字段串的正则表达式应该怎么写?

解决方案 »

  1.   

     string[] str = { "/template/cn/company.html", "/template/en/company.html" };         
                foreach (string s in str)
                {               
                  string[] ss=  s.Split(new char[] { '/', '.' });
                  Console.WriteLine(ss[ss.Length-2]);
                }          
    这个没用正则
      

  2.   


    Match m = Regex.Match(yourStr,@"(?<=/)[^/\.]+(?=\.)");
    MessageBox.Show(m.Value);
      

  3.   


    string yourStr = "/template/cn/company.html\r\n/template/en/company.html\r\n";
    MatchCollection mc = Regex.Matches(yourStr, @"(?<=/)[^/\.]+(?=\.)");
    foreach (Match m in mc)
    {
        MessageBox.Show(m.Value);
    }
      

  4.   


    就是从/template/cn/company.html   ,/template/en/company.html
    这样的字符串里面取到 company
      

  5.   


    /template/cn/company.html
    /template/en/company.html
    /template/jp/company.html
    /template/er/company.html
    /template/ph/company.html就比如说这样的一条条循环出来的,我想取每一个条数据里面的company
      

  6.   

    就是要取一个URL最终页面的文件名是吧?
    (?<=/)[^/]*(?=\.)
    用这个正则试试
      

  7.   

      string[] str = { "/template/cn/company.html", "/template/en/company.html" };
               Regex re = new Regex(@"(?<=/)[^/.]+(?=\.)");
                foreach (string s in str)
                {
                   Console.WriteLine(re.Match(s).Value);
               
                }
    6楼代码可行