title: Remove unnecessary attributes from html tag using JavaScript RegEx
body: <p>I'm newbie to regular expressions, trying to filter the HTML tags keeping only required (src / href / style) attribute with their values and remove unnecessary attributes. While googling I found a regular expression to keep only "src" attribute, hence my modified expression is as follows:</p>
  
  <pre><code>&lt;([a-z][a-z0-9]*)(?:[^&gt;]*(\s(src|href|style)=['\"][^'\"]*['\"]))?[^&gt;]*?(\/?)&gt;
  </code></pre>
  
  <p>Its working fine but the only problem is, if one tag contains more than one required attribute then it keeps only the last matched single attribute and discards the rest.</p>
  
  <p>I'm trying to clean following text</p>
  
  <pre><code>&lt;title&gt;Hello World&lt;/title&gt;
  &lt;div fadeout"="" style="margin:0px;" class="xyz"&gt;
      &lt;img src="abc.jpg" alt="" /&gt;
      &lt;p style="margin-bottom:10px;"&gt;
          The event is celebrating its 50th anniversary K&amp;ouml;&amp;nbsp;
          &lt;a style="margin:0px;" href="http://www.germany.travel/"&gt;exhibition grounds in Cologne&lt;/a&gt;.
      &lt;/p&gt;
      &lt;p style="padding:0px;"&gt;&lt;/p&gt;
      &lt;p style="color:black;"&gt;
          &lt;strong&gt;A festival for art lovers&lt;/strong&gt;
      &lt;/p&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>at <a href="https://regex101.com/#javascript" rel="nofollow">https://regex101.com/#javascript</a> using aforementioned expression with <code>&lt;$1$2$4&gt;</code> as substitution string and getting following output:</p>
  
  <pre><code>&lt;title&gt;Hello World&lt;/title&gt;
  &lt;div style="margin:0px;"&gt;
      &lt;img src="abc.jpg"/&gt;
      &lt;p style="margin-bottom:10px;"&gt;
          The event is celebrating its 50th anniversary K&amp;ouml;&amp;nbsp;
          &lt;a href="http://www.germany.travel/"&gt;exhibition grounds in Cologne&lt;/a&gt;.
      &lt;/p&gt;
      &lt;p style="padding:0px;"&gt;&lt;/p&gt;
      &lt;p style="color:black;"&gt;
          &lt;strong&gt;A festival for art lovers&lt;/strong&gt;
      &lt;/p&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Problem is "style" attribute is discarded from anchor tag. 
  I have tried to replicate the <code>(\s(src|href|style)=['\"][^'\"]*['\"])</code> block using * operator, {3} selector and much more but in vain.
  Any suggestions???</p>