// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Text; using System.Text.RegularExpressions; namespace E { public class Program { private static readonly Regex re = new Regex(@"(.*?_(\d+).*?_(\d+).*\r\n)(.*\r\n.*\r\n.*\r\n)", RegexOptions.Compiled); public static string XReplace(string s) { StringBuilder res = new StringBuilder(""); int ix = 0; foreach(Match m in re.Matches(s)) { res.Append(s.Substring(ix, m.Index - ix)); if(int.Parse(m.Groups[2].Value) > 10 && int.Parse(m.Groups[3].Value) > 10) { res.Append(m.Groups[1].Value); res.Append("x\r\nx\r\nx\r\n"); } else { res.Append(m.Groups[0].Value); } ix = m.Index + m.Length; } res.Append(s.Substring(ix)); return res.ToString(); } public static void Main(string[] args) { string s = @"a b_11 c_12 d e f g_9 h_10 i j k l m n_13 o p_14 q r s t u"; Console.WriteLine(s); } } }