title: Python: match regex in BeautifulSoup text
body: <p>I'm trying to crawl a webpage that has an ng-template script (for Angular, I think) in the browser-code:</p>
  
  <pre><code>&lt;script type="text/ng-template" id="modals/location-address.html"&gt;
      &lt;div
        class= "modal-address"
        style="background-image: url('https://cdn.ratemds.com/media/locations/location/map/605300-map_kTGdM7j.png');"
      &gt;
        &lt;div class="modal-body"&gt;
  
            &lt;address&gt;
  
                &lt;strong&gt;Sunshine Perinatology&lt;/strong&gt;&lt;br&gt;
  
  
  
                7421 Conroy Windermere Road&lt;br&gt;
  
                  null&lt;br&gt;
  
  
  
              Orlando,
              FL,
              United States&lt;br&gt;
  
  
                32835
  
            &lt;/address&gt;
  
        &lt;/div&gt;
  
        &lt;div class="modal-footer"&gt;
          &lt;a class="btn btn-default" ng-click="close()"&gt;Close&lt;/a&gt;
  
            &lt;a
              href="https://maps.google.com?q=sunshine%20perinatology%2C%207421%20conroy%20windermere%20road%2C%20orlando%2C%20florida%2C%20united%20states%2C%2032835"
              class="btn btn-success"
              target="_blank"
            &gt;
              Get Directions
            &lt;/a&gt;
  
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/script&gt; 
  </code></pre>
  
  <p>This is an example code from the browser inspector. What I did till now is using Selenium to get the page and then using BeautifulSoup to crawl the tags. For this certain example my code looks the following (without the code part for selenium):</p>
  
  <pre><code>import html.parser
  import re
  
  h = html.parser.HTMLParser()
  
  select = soup.find("script", id="modals/location-address.html")
  items = []
  for item in select.contents:
      items.append(str(item).strip())
  
  newContents = '&lt;select&gt;' + ''.join(items).replace('--','')
  newSelectSoup = bs.BeautifulSoup(h.unescape(newContents), 'lxml')
  
  pattern = "([A-Z0-9])\w+"
  re.findall(pattern, newSelectSoup.find('address').text)
  </code></pre>
  
  <p>So, my approach till now, with some hacking and trial&amp;error, is to crawl the content within the <code>&lt;address&gt;</code> tag. After that I was thinking of using regex to extract the needed parts of the text that is:</p>
  
  <p><code>Sunshine Perinatology, 7421 Conroy Windermere, Orlando, FL, United States, 32835</code></p>
  
  <p>However, when executing <code>re.findall(pattern, newSelectSoup.find('address').text)</code>, the result looks the following:</p>
  
  <p><code>['S', 'P', '7', 'C', 'W', 'R', 'O', 'F', 'U', 'S', '3']</code></p>
  
  <p>So I only get the first letter/number of the word and I'm not sure why. Is there a way to get all of the strings with this approach? Since I'm absolutely unfamiliar with regex, I was trying out the pattern with the soup output on regexr.com, which matches all the words perfectly.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Since I didn't find a solution to crawl the content of the <code>&lt;address&gt;</code>from the above browser-code, I did the intermediate step to create a new soup with HTMLParser. So when I crawl for the address tag with the new soup code, the output for <code>newSelectSoup.find('address').text</code> is the following:</p>
  
  <p><code>'\nSunshine Perinatology\n            \n\n            \n              7421 Conroy Windermere Road\n              \n                null\n              \n            \n\n            Orlando,\n            FL,\n            United States\n\n            \n              32835\n            \n          '</code></p>
  
  <p>My goal was to use regex on this soup output to extract the above output that doesn't capture all the line breaks and the <code>null</code> value in between</p>