求一条正则表达式 /template/cn/company.html/template/en/company.html这样的路径里面取company字段串的正则表达式应该怎么写? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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]); } 这个没用正则 Match m = Regex.Match(yourStr,@"(?<=/)[^/\.]+(?=\.)");MessageBox.Show(m.Value); 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);} 就是从/template/cn/company.html ,/template/en/company.html这样的字符串里面取到 company /template/cn/company.html/template/en/company.html/template/jp/company.html/template/er/company.html/template/ph/company.html就比如说这样的一条条循环出来的,我想取每一个条数据里面的company 就是要取一个URL最终页面的文件名是吧?(?<=/)[^/]*(?=\.)用这个正则试试 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楼代码可行 时区转换的问题 三个同名文本框怎么获得内容【100分】 钩子问题,wince系统,vs.2005开发,树形控件没法响应鼠标事件,也就是触摸屏事件。 Using语句块关闭连接问题!!!!!!!急 求助... 100分... :) WinForm交流! 如何在后台循环取一部分字段里的值 combox控件的上下箭头事件 再出一个幼稚的问题,RSA.KEY中哪个是公钥,哪个是密钥 人员选择 网站流量统计 急 TabPage中的控件绑定问题
foreach (string s in str)
{
string[] ss= s.Split(new char[] { '/', '.' });
Console.WriteLine(ss[ss.Length-2]);
}
这个没用正则
Match m = Regex.Match(yourStr,@"(?<=/)[^/\.]+(?=\.)");
MessageBox.Show(m.Value);
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);
}
就是从/template/cn/company.html ,/template/en/company.html
这样的字符串里面取到 company
/template/cn/company.html
/template/en/company.html
/template/jp/company.html
/template/er/company.html
/template/ph/company.html就比如说这样的一条条循环出来的,我想取每一个条数据里面的company
(?<=/)[^/]*(?=\.)
用这个正则试试
Regex re = new Regex(@"(?<=/)[^/.]+(?=\.)");
foreach (string s in str)
{
Console.WriteLine(re.Match(s).Value);
}
6楼代码可行