Writing regular expression in python
<p>I am weak in writing regular expressions so I'm going to need some help on the one. I need a regular expression that match to <code>section 7.01</code> and then <code>(a)</code></p>

<p>Basically with <code>section</code> can be followed by any number like <code>6.1</code>/<code>7.1</code>/<code>2.1</code></p>

<p>Examples:</p>

<pre><code>SECTION 7.01. Events of Default. If any of the following events
("Events of Default") shall occur:
          (a) any Borrower shall fail to pay any principal of any Loan when and
     as the same shall become due and payable, whether at the due date thereof
     or at a date fixed for prepayment thereof or otherwise;
</code></pre>

<p>I am trying to write an regular expression which can give me groups which contains these</p>

<p>Group 1</p>

<pre><code>SECTION 7.01. Events of Default. If any of the following events
("Events of Default") shall occur:
</code></pre>

<p>Group 2</p>

<pre><code>(a) any Borrower shall fail to pay any principal of any Loan when and
     as the same shall become due and payable, whether at the due date thereof
     or at a date fixed for prepayment thereof or otherwise;
</code></pre>

<p>Also there can be more points after <code>(a)</code> like <code>b</code> and so on.</p>

<p>Please help me out in writing an regular expression.</p>

<p>You can use the following approach, however, multiple <strong>assumptions</strong> are made. The section headers must begin with <code>SECTION</code> and end with a colon <code>:</code>. Secondly the sub-sections must begin with <em>matching</em> parenthesis', and end with a semi-colon. </p>

<pre><code>import re
def extract_groups(s):
    sanitized_string = ''.join(line.strip() for line in s.split('\n'))
    sections = re.findall(r'SECTION.*?:', sanitized_string)
    sub_sections = re.findall(r'\([a-z]\).*?;', sanitized_string)
    return sections, sub_sections
</code></pre>

<p><strong>Sample Output:</strong></p>

<pre><code>&gt;&gt;&gt; s = """SECTION 7.01. Events of Default. If any of the following events
("Events of Default") shall occur:
          (a) Whether at the due date thereof
     or at a date fixed for prepayment thereof or otherwise;

          (b) Test;
SECTION 7.02. Second section:"""
&gt;&gt;&gt; print extract_groups(s)
(['SECTION 7.01. Events of Default. If any of the following events("Events of Default") shall occur:', 'SECTION 7.02. Second section:'], 
['(a) Whether at the due date thereofor at a date fixed for prepayment thereof or otherwise;', '(b) Test;'])
</code></pre>

python regex