询问一个正则用法 xxx.abc.com我想问如上面的一个字符串,即如果出现 ".abc.com" 时就匹配,并将xxx取出还有一个条件时取时需要排除www.abc.com这种情况。谢谢各位了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 @"^(?!www\.)(?<name>\w+)\.abc\.com$" 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,把你这分都给我,我就能升星了. 有可能是 abc bacdef aaaaa 这样不定的 @"^(?!www\.)(\w+)\.abc\.com$"// $1 就是你所要的。 做二级域名泛解析??用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) + "$"; } 用正则分组. 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; winfrom 时间格式 XML注释 webservers+AutoCompleteExtender的二次查询赋值,解决问题+100分 winform程序加背景图片,程序变卡。 C#如何让几个人同时操作同一个SQL server 2000数据库同一个表而不发生冲突 打印机总是按照A4的长度走纸,怎么解决? 如何使 ListView 表头居中,数据左对齐 SurfaceRT视频播放器 winfrom怎么解析这样的json 新手求助 急!!!!!!!!!!!!!!!!! 请教FileSystemWatcher监控文件遇到的奇怪问题
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,把你这分都给我,我就能升星了.
// $1 就是你所要的。
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) + "$";
}
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;