CSharp · Console
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
public class Program
{
public static void Main()
{
var input = @"<Hello> [World]!";
var regex = new Regex(@"(?<=\<).*(?=\>)|(?<=\[).*(?=\])");
var index = 0;
var replacements = new List<string>();
var formatString = regex.Replace(input, (m) =>
{
replacements.Add(m.Value);
return String.Format("{{{0}}}", index++);
});
Console.WriteLine(formatString);
Console.WriteLine(String.Join(Environment.NewLine, replacements.Select((v, i) => i + ": " + v).ToArray()));
}
}