using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.RegularExpressions; public class Test { public static void Main() { var input = "text, *text*, text, text, (text), [text], [some_text with _*](http://.....) *text*, text, text, (text), [text]"; var pattern = @"(\[[^][]*]\([^()]*\))|[][()*_]"; Console.WriteLine(Regex.Replace(input, pattern, m => m.Groups[1].Success ? m.Groups[1].Value : $@"\{m.Value}")); } }