using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"<section.*id=""section[\d]*""[\s\S]*?<\/section>";
string input = @"<!DOCTYPE html>
<html lang=""en"">
<head>
<title>Whatever</title>
</head>
<body>
<section class=""all-classes"" id=""section1-do-not-remove-section"">
content2
content
</section>
<section class=""all-classes"" id=""section2"">
content
content2
</section>
</body>
<section class=""all-classes"" id=""section3"">
content
<div class=""all-classes"" id=""section4"">
anything
whatever
</div>
</section>
<section class=""all-classes"" id=""section5-do-not-remove-section"">
content
</section>
<section class=""all-classes"" id=""section6"">
content
</section>
<section class=""all-classes"" id=""section7"">
content
</section>
";
RegexOptions options = RegexOptions.Multiline;
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