title: How can i use regex pattern the first from the end to have the last sentence in python
body: <p>I have the netx text:</p>
  
  <pre><code>"TITULO: Albedo SUBTITULO Y PARRAFO: ===Trees===
  Because forests generally have a low albedo, (the majority of the ultraviolet and [[visible spectrum]] is absorbed through [[photosynthesis]])
  "
  
  "TITULO: Albedo SUBTITULO Y PARRAFO: ==Human activities==
  Human activities (e.g., deforestation, farming, and urbanization) change the albedo of various areas around 
  "TITULO: Abraham Lincoln SUBTITULO Y PARRAFO: ===U.S. House of Representatives, 1847–1849===
  [[File:Abraham Lincoln by Nicholas Shepherd, 1846-crop.jpg|thumb|upright|alt=Middle 
  </code></pre>
  
  <p>I want to create a dataframe using regex in python:</p>
  
  <pre><code>Tile                   Head                          TEXT
  Albedo                 Trees                         Because forests generally have a low  ...([[photosynthesis]])
  Albedo                 Human activities              Human activities (e.g., de...areas around 
  Abraham Lincoln        U.S. House of..1849           [[File:Abraham Lincoln by... line Whig,
  </code></pre>
  
  <p>I have this code, the first and the second colums it works but the third column i don´t know 
  How can i get from last == or === or ==== forward ? That is to say.</p>
  
  <p>Because forests generally have a low albedo, (the majority of the ultraviolet and [[visible spectrum]] is absorbed through [[photosynthesis]])</p>
  
  <p>Human activities (e.g., deforestation, farming, and urbanization) change the albedo of various areas around </p>
  
  <p>[[File:Abraham Lincoln by Nicholas Shepherd, 1846-crop.jpg|thumb|upright|alt=Middle</p>
  
  <pre><code>import re
  from collections import defaultdict
  import pandas as pd
  
  pandas_dict = defaultdict(list)
  
  with open("datos_titulos.csv", "r") as f:
      for line in f:
  
  
          pat = r"TITULO: (.*) SUBTITULO Y PARRAFO: ==(.*?)==|rTITULO: (.*) SUBTITULO Y PARRAFO: ===(.*?)==="
          pat2 = r"TITULO: (.*) SUBTITULO Y PARRAFO: ==(.*?)==$|rTITULO: (.*) SUBTITULO Y PARRAFO: ===(.*?)===$"
  
          if re.search(pat, line) :
  
              pandas_dict["title"].append(re.search(pat, line).group(1))
              pandas_dict["head"].append(re.search(pat, line).group(2))
          if re.search(pat2, line) :
  
              pandas_dict["text"].append(re.search(pat2, line).group(2))
  df = pd.DataFrame(pandas_dict) 
  </code></pre>