title: Searching for HTML Elements based on a specific word in the element string
body: <p>Trying to create a program that can find and replace tags in certain, specified elements using the Beautiful Soup module. However - I’m having trouble figuring out how to “find” these elements by “searching” via a specific word that is found in the element’s string. Assuming I can get my code to “find” these elements by their specified word-in-string, I would then “unwrap” the element’s “p” tag and “wrap” them in their new “h1” tag.  </p>
  
  <p>Here’s some example HTML code as the input: </p>
  
  <pre><code>&lt;p&gt; ExampleStringWord#1 needs to “find” this entire element based on the "finding" of the first word &lt;/p&gt;
  &lt;p&gt; Example#2  this element ignored &lt;/p&gt;
  &lt;p&gt; ExampleStringWord#1 needs to find this entire element as well because the first word of this string is what I’m “searching” for, even though the wording after the first word in the string is different &lt;p&gt;
  </code></pre>
  
  <p>Here’s my code so far (searching by “ExampleStringWord#1”):</p>
  
  <pre><code>for h1_tag in soup.find_all(string="ExampleStringWord#1"):
              soup.p.wrap(soup.h1_tag("h1"))
  </code></pre>
  
  <p>If using the example HTML input above, I want the code to come out like this: </p>
  
  <pre><code>&lt;h1&gt; ExampleStringWord#1 needs to “find” this entire element based on the "finding" of the first word &lt;/h1&gt;
  &lt;p&gt; Example#2  this element ignored &lt;/p&gt;
  &lt;h1&gt; ExampleStringWord#1 needs to find this entire element as well because the first word of this string is what I’m “searching” for, even though the wording after the first word in the string is different &lt;h1&gt;
  </code></pre>
  
  <p>However, my code only finds the elements that explicitly contain “ExampleStringWord#1” exclusively , and will exclude elements that contain any string wording past that. 
  I’m convinced that I will somehow need to utilize the regular expressions to find my specified word’s (in addition to whatever string wording that follows) element. However, I’m not super familiar with Regular Expressions so I’m not sure how to approach this in conjunction with the BeautifulSoup module.</p>
  
  <p>Also – I’ve reviewed the documentation in Beautiful Soup for passing in a Regular Expression as a filter (<a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/#a-regular-expression" rel="nofollow noreferrer">https://www.crummy.com/software/BeautifulSoup/bs4/doc/#a-regular-expression</a>), but I’ve not been able to get it to work in my case. I've also reviewed other posts here related to passing regular expressions through beautiful soup but I've not found anything that has adequately addressed my issue.
  Any help appreciated! </p>