fork(1) download
  1. // http://stackoverflow.com/q/33592525/5290909
  2. using System;
  3. using System.Text.RegularExpressions;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. string pattern = @"<script.*>[^>]*<\/script>";
  10. var re = new Regex( pattern);
  11. var text = @"
  12. <html>
  13. <head>
  14. <title>
  15. </title>
  16.  
  17. <script src=""adasdsadsda.js""></script>
  18. </head>
  19.  
  20. <body>
  21. <script type='javascript'>
  22. var a = 1 + 2;
  23.  
  24. alert('a');
  25. </script>
  26. </body>
  27.  
  28. <script></script>
  29. </html>
  30. ";
  31.  
  32.  
  33. MatchCollection matches = re.Matches(text);
  34. for (int mnum = 0; mnum < matches.Count; mnum++)
  35. { //loop matches
  36. Match match = matches[mnum];
  37. Console.WriteLine("Match #{0} - Value: {1}", mnum + 1, match.Value);
  38. }
  39. }
  40. }
Success #stdin #stdout 0.11s 24424KB
stdin
Standard input is empty
stdout
Match #1 - Value: <script src="adasdsadsda.js"></script>
Match #2 - Value: <script type='javascript'>
				        var a = 1 + 2;
				
				        alert('a');
				    </script>
Match #3 - Value: <script></script>