我写的全文关键字变超链。关于图片alt有关键词问题
public static string getContentBysystenkeyword(object obj)
{
string content = "";
if (obj == null || obj.ToString().Trim() == "")
{
return "";
}
content = obj.ToString();
List<MSystemKeyword> list = HttpContext.Current.Cache["SystemKeyword"] as List<MSystemKeyword>;
if (list == null)
{
BSystemKeyword syskeywordbll = new BSystemKeyword();
syskeywordbll.path = HttpContext.Current.Server.MapPath("/App_Data/SystemKeywords.xml");
list = syskeywordbll.getList("Enabled=True");
if (list == null)
list = new List<MSystemKeyword>();
System.Web.Caching.CacheDependency dep = new System.Web.Caching.CacheDependency(
HttpContext.Current.Server.MapPath("/App_Data/SystemKeywords.xml"));
HttpContext.Current.Cache.Insert("SystemKeyword", list, dep);
}
foreach (MSystemKeyword m in list)
{
string target = " target=\"_blank\"";
content = System.Text.RegularExpressions.Regex.Replace(content, "(?<=[^>]*)(" + m.LookExpression + ")(?![^<]*</a>)", "<a title=\"" + m.Title + "\""
+ "alt=\"" + m.Alt + "\"" + target + " href=\"" + m.Link + "\">$1</a>");
}
return content;
}
如果一个关键字:中国
一个单页面出现中国的会加一个链接。如果图片的Title或alt出现中国,那么图片就坏掉了
有高手遇到过这问题吗?求助 --------------------编程问答-------------------- 把那些不需要替换的情况给筛选出来
或者把需要替换的给筛选出来
你需要把这些东西给归类了,然后让一大牛给写一正则就搞定了 --------------------编程问答-------------------- 正则匹配 --------------------编程问答--------------------
关键是找不到这个大牛呀 --------------------编程问答--------------------
老兄,有吗 --------------------编程问答-------------------- 有高手吗? --------------------编程问答--------------------
首先你需要把你的需求给叙述明白了 哪些“中国”是需要替换的 哪些中国是不需要替换的
你总得把这两种情况给叙述明白了 人也好写正则哇 --------------------编程问答--------------------
碰到<img>的不要求输出判断关键字。 屏蔽<img> --------------------编程问答-------------------- 求关注,求大牛,求解答 --------------------编程问答-------------------- 求正则高手,在线wating..... --------------------编程问答-------------------- 看看这个帖子里的正则符合你的要求不,俺不会正则给关键词加超链接,但忽略已有的超链接,及所有标签属性的内容 --------------------编程问答-------------------- 有么有高手啊,我都等待一个星期了,高手帮忙解决下啊 --------------------编程问答-------------------- 真没人能回答上来了呀? --------------------编程问答-------------------- 哎,败了。 --------------------编程问答-------------------- 高手请进 --------------------编程问答-------------------- 假设你遇到了一个语法分析之后才能翻译出来结果的需求,却去妄想用什么正则来“解决”,这不就是太幼稚了嘛。
正则只能干最简单最低级的工作,它只是分析基本单词用来作为语法分析程序的输入,而不是搞高级的翻译工作的! --------------------编程问答-------------------- 你应该去找一个html语法分析程序,这个程序给出html语法结构树。 --------------------编程问答--------------------
那你给个例子我看下
补充:.NET技术 , ASP.NET