How To Replace Link Target using Regular Expression

private string ReplaceBlankTarget(string text)
{
    string pattern = @"<a href=""https:\/\/(?<link>[^""]+)"" target=""_blank"">";
    string substitution = @"<a href=""https:\/\/${link}"" target=""_self"">";

    RegexOptions options = RegexOptions.Multiline;

    Regex regex = new Regex(pattern, options);
    return regex.Replace(text, substitution);
}

 

Comments