title: Parsing text from a table of contents using regex
body: <p>Following is the text I'd like to parse, stored in variable named "toc"</p>
  
  <p></p>
  
  <pre><code>                                  Table of Contents
  I.   INTRODUCTION          ....................................                                  1
  II.  FACTUAL ASPECTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .     2
       A.   The Clean Air Act . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  3
       B.   EPA's Gasoline Rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .    3
            1.     Establishment of Baselines . . . . . . . . . . . . . . . . . . . . . . . .      3
            2.     Reformulated Gasoline . . . . . . . . . . . . . . . . . . . . . . . . . .       4
            3.     Conventional Gasoline (or "Anti-Dumping Rules") . . . . . . . .                 4
       C.   The May 1994 Proposal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .      5
  III. MAIN ARGUMENTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .      5
       A.   General          ....................................                                  5
       B.   The General Agreement on Tariffs and Trade . . . . . . . . . . . . . . . .             6
            1.     Article I - General Most-Favoured-Nation Treatment . . . . . . .                6
            2.     Article III - National Treatment on Internal Taxation
                   and Regulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .    7
                   a)      Article III:4 . . . . . . . . . . . . . . . . . . . . . . . . . . . .   7
                   b)      Article III:1 . . . . . . . . . . . . . . . . . . . . . . . . . . . .  14
            3.     Article XX - General Exceptions . . . . . . . . . . . . . . . . . . . .        15
            4.     Article XX(b) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  15
                   a)      "Protection of Human, Animal and Plant Life
                           or Health" . . . . . . . . . . . . . . . . . . . . . . . . . . . . .   15
                   b)      "Necessary" . . . . . . . . . . . . . . . . . . . . . . . . . . . .    15
            5.     Article XX(d) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  21
            6.     Article XX(g) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  22
                   a)      "Related to the conservation of exhaustible natural
                           resources..." . . . . . . . . . . . . . . . . . . . . . . . . . . . .  22
                   b)      "... made effective in conjunction with restrictions
                           on domestic production or consumption" . . . . . . . . . .             23
            7.     Preamble to Article XX . . . . . . . . . . . . . . . . . . . . . . . . . .     23
            8.     Article XXIII - Nullification and Impairment . . . . . . . . . . . .           25
  </code></pre>
  
  <p>I want the result like this:</p>
  
  <pre><code>['I.INTRODUCTION ...... 1', 'A. The Clean Air Act ....3', 'B. EPA\'s Gasoline Rule ... 3', (AND_SO_ON) ]
  </code></pre>
  
  <p>INPUT:</p>
  
  <pre><code>re.search(r"((?&lt;=(\n))\s+(?P&lt;name&gt;[A-Z \.]*?)(\n))", toc_s).group() 
  </code></pre>
  
  <p>OUTPUT:</p>
  
  <pre><code>---------------------------------------------------------------------------
  AttributeError                            Traceback (most recent call last)
  &lt;ipython-input-64-4aa240f6e378&gt; in &lt;module&gt;()
  ----&gt; 1 re.search(r"((?&lt;=(\n))\s+(?P&lt;name&gt;[A-Z \.]*?)(\n))", toc_s).group()
  
  AttributeError: 'NoneType' object has no attribute 'group'
  </code></pre>
  
  <p>What was my problem?</p>