问问题
1824 次
3 回答
3
这应该可以按需要工作:
Regex.Replace(text, "<a(((?!target=).)*)\">", "<a$1\" target=\"_parent\">")
需要进行少量假设,即您关闭的每个开始锚标记必须"
在关闭带有字符的开始标记之前具有该>
字符。
即<a......">
我的链接</a>
于 2013-03-04T14:25:12.660 回答
1
为您解决方案:
Regex _r = new Regex("<a (.+?)>");
foreach (Match m in _r.Matches(text))
{
string Link = m.Groups[0].Value;
if (!Link.Contains("target"))
text = text.Replace(Link, string.Format("{0} target=\"_parent\">", Link.Substring(0, Link.Length - 1)));
}
于 2013-03-04T12:52:16.483 回答
0
可能会像这样更容易吗?:
if (false == text.Contains("target="))
{
Regex.Replace(text, "<(a)([^>]+)(((?! target=).)*$)([^>]+)>", "<$1 target=\"_parent\" $2 $3>");
}
于 2013-03-04T12:50:57.650 回答