title: Select first two words of h2 tag and wrap in span tag
body: <p>I wanted to find all h2 tags on a page and then wrap first two words in a span tag. I have checked <a href="https://stackoverflow.com/questions/15182113/select-first-2-words-with-jquery-and-wrap-them-with-span-tag/15182155#15182155">this stackoverflow question</a>, but it didn't help me.</p>
  <p>I am able to do as per this link and dd span to first 2 words, but the only issue is that if I have html inside h2 tag for eg I have hyperlink inside h2 tag.</p>
  <p>Can anyone please help me how to make this code so as html is ignored and only first two words are considered?</p>
  <p>Any help is really appreciated!</p>
  <hr />
  <h3>My Fiddle :</h3>
  <p><a href="https://jsfiddle.net/rigid/jornvLee/2/" rel="nofollow noreferrer"><strong>JSFiddle</strong></a></p>
  <hr />
  <h3>My JS :</h3>
  <pre><code>jQuery(document).ready(function($){ 
      jQuery('h2').html(function (i, html) {
          return html.replace(/(\w+\s\w+)/, '&lt;span&gt;$1&lt;/span&gt;')
      });
  });
  </code></pre>
  <hr />
  <h3>My HTML :</h3>
  <pre><code>&lt;h2&gt;
      &lt;a title=&quot;test post 2&quot; href=&quot;#&quot;&gt;
          test text dolor sit enum
      &lt;/a&gt;
  &lt;/h2&gt;
  &lt;h2&gt;lorem ipsum dolor sit enum&lt;/h2&gt;
  </code></pre>