using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"<script>
(?:(?!</script>)[\s\S])*
(?:google-analytics)
(?:(?!</script>)[\s\S])*
</script>";
string input = @" <script src=""js/min/test.min.js""></script>
<script>
$('#buttons').share({
networks: ['twitter'],
});
</script>
<!--[if lt IE 9]>
<script src=""js/plugins/html5shiv.js""></script>
<script src=""js/plugins/selectivizr.js""></script>
<![endif]-->
<!-- location for site scripts -->
<div id=""scripts"">
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-55555-1', 'auto', 'tracker');
ga('tracker.send', 'pageview');
</script></div> <!-- /#lpsite-scripts -->
<div id=""lppage-scripts"">
</div>
<script type=""text/javascript"" src=""js/min/form-validation.min.js""></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-55555-1', 'auto', 'tracker');
ga('lptracker.send', 'pageview');
</script>
";
RegexOptions options = RegexOptions.IgnorePatternWhitespace;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx