title: Python: Regular expression to extract text between any two tags in a html
body: <p>I tried using <code>"&lt;.+&gt;\s*(.*?)\s*&lt;\/?.+&gt;"</code> on a HTML file. The following is the Python code I used</p>
  
  <pre><code>import re
  
  def recursiveExtractor(content):
      re1='(&lt;.+&gt;\s*(.+?)\s*&lt;\/?.+&gt;)'
      m = re.findall(re1,content)
      if m:
          for (id,item) in enumerate(m):
              text=m[id][1]
              if text:print text,"\n"
  
  f = """
  &lt;div class='a'&gt;
        &lt;div class='b'&gt;
          &lt;div class='c'&gt;
              &lt;button&gt;text1&lt;/button&gt;
              &lt;div class='d'&gt;text2&lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  """
  recursiveExtractor(f)
  </code></pre>
  
  <p>But it skips some text since HTML is nested and regex restarts search from the end of the matched part.</p>
  
  <p>For the above input,
  the output is </p>
  
  <pre><code>&lt;div class='b'&gt;
  
  &lt;div class='d'&gt;text2&lt;/div&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>But the expected Output is:</p>
  
  <pre><code>text1
  
  text2
  </code></pre>
  
  <p>Edit:
  I read that HTML is not a regular language and hence cant be parsed.From what I understand, it is not possible to parse  .*  (ie with same closing tags). 
  But what I need would be text between any tags, for instance  text1  text2  text3  So I am fine with a list of "text1","text2","text3" </p>