title: Ignoring irrelevant section in regex
body: <p>I have the following text: (this is closely related to <a href="https://stackoverflow.com/questions/69997111/using-regex-to-select-specific-section-of-a-text">this</a> but not similar)</p>
  <pre><code>text = '7\n\x0c\n7.\tA B C\n\n7.1\tbla bla bla .\n\n7.2\tanother bla bla \n\n7.3\tand another one.\n\n8.\tX Y Z\n\n8.1\tha ha ha \n\n(a)\thohoho ;\n\n(b)\thihihi,\n\n8'
  </code></pre>
  <p>I wish to select the section 7 only such that I get:</p>
  <pre><code>7.  A B C
  
  7.1 bla bla bla .
  
  7.2 another bla bla 
  
  7.3 and another one.
  </code></pre>
  <p>So I do:</p>
  <pre><code>print(re.findall(r'^\d+\.\s*A B C[^\S\n]*(?:\n\n.+)*', text, re.M)[0])
  </code></pre>
  <p>which gives:</p>
  <pre><code>7.  A B C
  
  7.1 bla bla bla .
  
  7.2 another bla bla 
  
  7.3 and another one.
  
  8.  X Y Z
  
  8.1 ha ha ha 
  
  (a) hohoho ;
  
  (b) hihihi,
  
  8
  </code></pre>
  <p>As you can see <code>8</code> comes after <code>8.1</code>. So this seems to be confusing for the regex, I wonder what can I do in this case?</p>
  <p>Note that the number of the sections can be different in general, so I can not do something like
  <code>re.findall(r'^7\..*', text, re.MULTILINE)</code> (namely A B C can be places in other sections).</p>