using System.Text.RegularExpressions;
public static void Main()
string input = $"[lime on white]File size:[/] [bold]\t{length,-10}[/]";
Console.WriteLine(input.StripCodes());
public static class StringExtensions
private static readonly Regex Whitespace = new(@"\s+");
public static string Flatten(this string sender)
=> sender is null or "" ?
Whitespace.Replace(sender.Trim(), " ");
public static string StripCodes(this string sender)
=> Regex.Replace(sender, @"\[[^]]*\]", "")