fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using System.Collections.Specialized;
  4. class Program
  5. {
  6. static void Main() {
  7. string s1 = @"want to find this text
  8. <p>I don't want to find this text</p>
  9. I want to find this text";
  10. var myRegex = new Regex(@"(?i)<(\w+).*?<\/\1[^>]*>|([a-z][a-z ]+)");
  11. var group1Caps = new StringCollection();
  12.  
  13. Match matchResult = myRegex.Match(s1);
  14. // put Group 2 captures in a list
  15. while (matchResult.Success) {
  16. if (matchResult.Groups[2].Value != "") {
  17. group1Caps.Add(matchResult.Groups[2].Value);
  18. }
  19. matchResult = matchResult.NextMatch();
  20. }
  21.  
  22. Console.WriteLine("\n" + "*** Matches ***");
  23. if (group1Caps.Count > 0) {
  24. foreach (string match in group1Caps) Console.WriteLine(match);
  25. }
  26.  
  27. Console.WriteLine("\nPress Any Key to Exit.");
  28. Console.ReadKey();
  29.  
  30. } // END Main
  31. } // END Program
Success #stdin #stdout 0.09s 34000KB
stdin
Standard input is empty
stdout
*** Matches ***
want to find this text
I want to find this text

Press Any Key to Exit.