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>I got this to work:</p>

<pre><code>s = """
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;
"""

r = r'(SECTION 7\.01\.[\s\w\.()"]*:)[\s]*(\(a\)[\s\w,]*;)'
mo = re.search(r, s)
print('Group 1: ' + mo.group(1))
print('Group 2: ' + mo.group(2))
</code></pre>

<p>If you wanted to make it generic, so you could grab the any number or section, you could try:</p>

<pre><code>r = r'(SECTION [1-9]\.[0-9]{2}\.[\s\w\.()"]*:)[\s]*(\([a-z]\)[\s\w,]*;)'
</code></pre>

python regex