0
4

3 に答える 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 に答える