$re = '/<section.*id="section[\d]*"[\s\S]*?<\/section>/m';
$str = '<!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>
';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
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 PHP, please visit: http://php.net/manual/en/ref.pcre.php