using System.Text.RegularExpressions;
public partial class Program
private static readonly Regex HTMLNeedReplace = new Regex("<(\\S+) *[^>]*>", RegexOptions.Compiled);
private static readonly Regex HTMLNeedReplaceNoBacktrack = new Regex("<(\\S+) *[^>]*>", RegexOptions.Compiled | RegexOptions.NonBacktracking);
public static void Main()
string string1 = $$"""<a href="Home?DashboardID=100100&TableName=Users&Search=UserID~224" jslink="1"><div class="PicAndDescPill"><img src="https:
string stringTmp = string1;
System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
for (int i = 0; i < 100000; i++)
MatchCollection matches = HTMLNeedReplace.Matches(stringTmp);
Console.WriteLine("Execution time (interpolation): {0} ms", sw.ElapsedMilliseconds);
for (int i = 0; i < 100000; i++)
MatchCollection matches = HTMLNeedReplaceNoBacktrack.Matches(stringTmp);
Console.WriteLine("Execution time (StringBuilder): {0} ms", sw.ElapsedMilliseconds);