字符串截取。路过请进! 本帖最后由 phpStaleFly 于 2010-12-10 17:49:17 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 document.getElementById("链接id").innerHTML;//获取东岸2公馆document.getElementById("链接id").href;//获取url,然后你在自己根据/ 截取一下就可以了 MatchCollection mc= Regex.Matches(str, @" <a[^> ]*href=([ ' " "]?)(? <url> [^ ' " "> \s]*)\1?[^> ]*> (? <text> [^ <]*) </a> ", RegexOptions.IgnoreCase); foreach (Match m in mc) { Response.Write(m.Groups[ "url"].Value.Substring(m.Groups[ "url"].Value.LastIndexof("/")))); Response.Write(m.Groups[ "text "].Value); } string str = "<div class=\"title\"><a href=\"http://fang.com/community/view/236713\" target=\"_blank\">东岸2公馆</a></div><div class=\"title\"><a href=\"http://fang.com/community/view/236638\" target=\"_blank\">万科清林径二期</a></div><div class=\"title\"><a href=\"http://fang.com/community/view/237893\" target=\"_blank\">德轩公寓</a></div>"; Regex regNum = new Regex(@"/\d+"); MatchCollection mcNum= regNum.Matches(str); for(int i=0;i<mcNum.Count;i++) Console.WriteLine(mcNum[i].Value.Trim('/')); Regex regChinese = new Regex(@"[\u4E00-\u9FA5]+"); MatchCollection mcChina = regChinese.Matches(str); for (int i = 0; i < mcChina.Count; i++) Console.WriteLine(mcChina[i].Value.Trim('/'));测试通过 //只要这两个固定的?其他的不要?//下面是获取你指定的那两项目//如果想获取全部的view后面的值还有文字的话正则替换成//Regex reg = new Regex(@"(?i)<a[^>]*?href=['""]?[^>]*?/view/(\d+)[^>]*?>(?<address>[^<]*?)<"); string result = ""; string str = "<div class=\"title\"><a href=\"http://fang.com/community/view/236713\" target=\"_blank\">东岸2公馆</a></div>" + "<div class=\"title\"><a href=\"http://fang.com/community/view/236638\" target=\"_blank\">万科清林径二期</a></div>" + "<div class=\"title\"><a href=\"http://fang.com/community/view/237893\" target=\"_blank\">德轩公寓</a></div>"; Regex reg = new Regex(@"(?i)<a[^>]*?href=['""]?[^>]*?/view/(236713)[^>]*?>(?<address>[^<]*?)<"); MatchCollection match = reg.Matches(str); foreach (Match m in match) { result += m.Groups[1].Value + "---" + m.Groups["address"].Value; } Response.Write(result); IE8 锚链接,IE offsetHeight 兼容问题(请各位前台高人帮忙) 关于项目报价的一个问题 在线等。。请各位大侠给些答案 网站工程文件和编译问题 求助:关于验证控件 求救高手,我的数据字段类型是text的,为什么我输入多行数据在数据库中只能保存部分,不能全部保存! 请大帮忙装备一台价格在5K以下用.NET比较爽一点的机器。 打开.ASPX页面时让一个TextBox获得焦点 IIS7.5配置问题 不能加载母版页 关于适配器的问题 恳请jQuery高手解答$.post()问题 图片轮转问题
document.getElementById("链接id").innerHTML;//获取东岸2公馆
document.getElementById("链接id").href;//获取url,然后你在自己根据/ 截取一下就可以了
foreach (Match m in mc)
{
Response.Write(m.Groups[ "url"].Value.Substring(m.Groups[ "url"].Value.LastIndexof("/"))));
Response.Write(m.Groups[ "text "].Value);
}
Regex regNum = new Regex(@"/\d+");
MatchCollection mcNum= regNum.Matches(str);
for(int i=0;i<mcNum.Count;i++)
Console.WriteLine(mcNum[i].Value.Trim('/')); Regex regChinese = new Regex(@"[\u4E00-\u9FA5]+");
MatchCollection mcChina = regChinese.Matches(str);
for (int i = 0; i < mcChina.Count; i++)
Console.WriteLine(mcChina[i].Value.Trim('/'));
测试通过
//只要这两个固定的?其他的不要?
//下面是获取你指定的那两项目
//如果想获取全部的view后面的值还有文字的话正则替换成
//Regex reg = new Regex(@"(?i)<a[^>]*?href=['""]?[^>]*?/view/(\d+)[^>]*?>(?<address>[^<]*?)<");
string result = "";
string str = "<div class=\"title\"><a href=\"http://fang.com/community/view/236713\" target=\"_blank\">东岸2公馆</a></div>"
+ "<div class=\"title\"><a href=\"http://fang.com/community/view/236638\" target=\"_blank\">万科清林径二期</a></div>"
+ "<div class=\"title\"><a href=\"http://fang.com/community/view/237893\" target=\"_blank\">德轩公寓</a></div>";
Regex reg = new Regex(@"(?i)<a[^>]*?href=['""]?[^>]*?/view/(236713)[^>]*?>(?<address>[^<]*?)<");
MatchCollection match = reg.Matches(str);
foreach (Match m in match)
{
result += m.Groups[1].Value + "---" + m.Groups["address"].Value;
}
Response.Write(result);