fork(1) download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. class Program
  5. {
  6. static void Main()
  7. {
  8. string s = "This <tag id=\"1\">string <inner><tag></tag></inner></tag> is <p>inside <b>of</b> another</p> string";
  9. Match m;
  10. do
  11. {
  12. m = Regex.Match(s, @"\A([\s\S]*)(<(\S+)[^[<>]*>[^<>]*</\3>)([\s\S]*)\Z");
  13. if (m.Success) {
  14. s = m.Groups[1].Value + "{0}" + m.Groups[4].Value;
  15. System.Console.WriteLine("Match: " + m.Groups[2].Value);
  16. }
  17. } while (m.Success);
  18. System.Console.WriteLine("Result: " + s);
  19. }
  20. }
Success #stdin #stdout 0.07s 38216KB
stdin
Standard input is empty
stdout
Match: <b>of</b>
Match: <p>inside {0} another</p>
Match: <tag></tag>
Match: <inner>{0}</inner>
Match: <tag id="1">string {0}</tag>
Result: This {0} is {0} string