using System.Text.RegularExpressions;
public static void Main()
string text = "<a href='https://mashinchi.ir/hello' target='_blank'>hello</a>";
string pattern = @"<a[\s]+[^>]*?href[\s]?=[\s\""\']+((?!https://bama.ir)(?!https://mashinchi.ir).*?)[\""\']+(.*?)>";
string replacement = @"<a rel=""nofollow"" href=""$1""$2>";
string result = Regex.Replace(text, pattern, replacement, RegexOptions.IgnoreCase);
Console.WriteLine(result);