using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"<!-- build-remove-start -->([^<]*(?:<(?!!-- build-remove-end -->)[^<]*)*)<!-- build-remove-end -->";
string input = @"<!DOCTYPE html>
<html lang=""en"">
<head>
<meta charset=""UTF-8"">
<title>Hello</title>
<!-- bower:css -->
<!-- endbower -->
<!-- inject:css -->
<!-- endinject -->
</head>
<body>
<h1>Hello World!</h1>
<!-- build-remove-start -->
<!-- bower:js -->
<script src=""../bower_components/jquery/dist/jquery.js""></script>
<!-- endbower -->
<!-- build-remove-end -->
<!-- inject:vendor:js -->
<!-- endinject -->
<!-- inject:js -->
<!-- endinject -->
<!-- inject:app:js -->
<!-- endinject -->
</body>
</html>";
foreach (Match m in Regex.Matches(input, pattern))
{
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