using System.Text.RegularExpressions;
private static readonly string _htmlSpanTo = "<span class=\"taio-renraku-to me-2\">To</span>";
private static readonly string _htmlImageTo = "<img class=\"{0}\" src=\"/{1}\">";
private static readonly string _htmlNoImageTo = "<span class=\"{0} profile-img-inline\"><i class=\"icofont-user-alt-7 {1}\"></i></span>";
private static readonly string _htmlSpanName = "<span class=\"fw-bold\">{0}</span>";
public static readonly string CommentTo = "[To:{0}]";
public static readonly string CommentToAll = "[toAll]";
public static void Main()
var pattern = new Regex(@"\[To:(\S+)\](.+\sさん)");
var replaceString = pattern.Replace(
"[To:8001]testap1 さん \n[To:2]西尾次郎 さん", new MatchEvaluator((Match match) => {
var profileImage = "abc";
return $"{_htmlSpanTo} " +
$"{string.Format(_htmlSpanName, match.Groups[2].Value)}";
replaceString = replaceString.Replace("[toAll]", $"{_htmlSpanTo} " +
$"{string.Format(_htmlSpanName, "All")}");
Console.WriteLine(replaceString);