title: How can I remove all tag's attributes except specific ones?
body: <p>I have this string: </p>
  
  <pre><code>var str = '&lt;p&gt;paragraph&lt;a&gt;link&lt;/a&gt;&lt;/p&gt;
             &lt;div class="myclass"&gt;
                 &lt;div&gt;something&lt;/div&gt;
                 &lt;div style="mystyle"&gt;something&lt;/div&gt;
                 &lt;b&gt;&lt;a href="#"&gt;link&lt;/a&gt;&lt;/b&gt;
                 &lt;b&gt;&lt;a href="#" name="a name"&gt;link&lt;/a&gt;&lt;/b&gt;
                 &lt;b style="color:red"&gt;bold&lt;/b&gt;
                 &lt;img src="../path" alt="something" /&gt;
                 &lt;img src="../path" alt="something" class="myclass" /&gt;
             &lt;/div&gt;';
  </code></pre>
  
  <p>I want to remove all attributes except <code>href</code>, <code>src</code>, <code>alt</code>. So this is expected result:</p>
  
  <pre><code>/* 
  &lt;p&gt;paragraph&lt;a&gt;link&lt;/a&gt;&lt;/p&gt;
  &lt;div&gt;
      &lt;div&gt;something&lt;/div&gt;
      &lt;div&gt;something&lt;/div&gt;
      &lt;b&gt;&lt;a href="#"&gt;link&lt;/a&gt;&lt;/b&gt;
      &lt;b&gt;&lt;a href="#"&gt;link&lt;/a&gt;&lt;/b&gt;
      &lt;b&gt;bold&lt;/b&gt;
      &lt;img src="../path" alt="something"&gt;
      &lt;img src="../path" alt="something"&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>How can I do that?</p>
  
  <hr>
  
  <p>I can just select them which isn't useful:</p>
  
  <p><a href="https://regex101.com/r/bB31js/1" rel="nofollow noreferrer"><code>/&lt;[a-z]+ .*?(href|src|alt)="[^"]+"/g</code></a></p>