xxx.abc.com
我想问如上面的一个字符串,即如果出现 ".abc.com" 时就匹配,并将xxx取出
还有一个条件时取时需要排除www.abc.com这种情况。
谢谢各位了

解决方案 »

  1.   

    @"^(?!www\.)(?<name>\w+)\.abc\.com$"
      

  2.   

                String inStr = "xxx.abc.com";
                Regex rx = new Regex(@"(?<name>.+)\.abc.com", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                MatchCollection matches = rx.Matches(inStr);
                string name = matches[0].Groups["name"].Value;
                if (name != "www")
                {
                    //name 就是你想要的.
                }
    LZ,把你这分都给我,我就能升星了.
      

  3.   

    有可能是 abc bacdef  aaaaa 这样不定的
      

  4.   

    @"^(?!www\.)(\w+)\.abc\.com$"
    // $1 就是你所要的。
      

  5.   

    做二级域名泛解析??用MS的URLRewriter简单修改一下就可以。以下为部分不完整代码:            string[] UserHost = app.Request.Url.Host.Split(new char[] { '.'});
                string domain2 = UserHost[0]; // log information to the Trace object.
    app.Context.Trace.Write("ModuleRewriter", "Entering ModuleRewriter"); // get the configuration rules
    RewriterRuleCollection rules = RewriterConfiguration.GetConfig().Rules; // iterate through each rule...
    for(int i = 0; i < rules.Count; i++)
    {
    //string lookFor = "^" + RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath, rules[i].LookFor) + "$";
    string lookFor = "^" + rules[i].LookFor + "$";
                    if (domain2 == "www" || domain2 == "dev")
                    {
                        requestedPath = app.Request.Path;
        lookFor = "^" + RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath, rules[i].LookFor) + "$";
                    }
      

  6.   

    用正则分组.
     string str="xxx.abc.com";
     Regex rx = new Regex(@"(?<name>.+)\.abc.com", RegexOptions.Compiled | RegexOptions.IgnoreCase);
     Mach m=rx.Mach(str)
     if(m.Success)
       string res=m.Groups["name"].Value;