title: Swift : Regex for remove all inline HTML attributes
body: <p>I want to clear all attributes from an HTML String text. I've found a lot of answers to do that but the problem is the grammer for regex is not working if we don't have a properly CSS style. and my situation was difficult because the HTML text that get from an API is not in order with its style.
  It might be like this: </p>
  
  <pre><code>&lt;p style="\"text-align:" justify;="" \"=""&gt;&lt;span style="\"font-size:" 13px;="" font-family:="" arial;="" text-decoration-skip-ink:="" none;\"=""&gt;&lt;b&gt;&lt;span style="font-size: 18px;"&gt;Angkor Wat&lt;/span&gt;&lt;/b&gt; is a temple complex in Cambodia and the largest religious monument in the world, on a site measuring 162.6 hectares (1,626,000 m2; 402 acres). It was originally constructed as a Hindu temple dedicated to the god Vishnu for the Khmer Empire, gradually transforming into a Buddhist temple towards the end of the 12th century. It was built by the Khmer King Suryavarman II in the early 12th century in Yaśodharapura, the capital of the Khmer Empire, as his state temple and eventual mausoleum. Breaking from the Shaiva tradition of previous kings, Angkor Wat was instead dedicated to Vishnu. As the best-preserved temple at the site, it is the only one to have remained a significant religious centre since its foundation. The temple is at the top of the high classical style of Khmer architecture. It has become a symbol of Cambodia, appearing on its national flag, and it is the country\'s prime attraction for visitors.&lt;/span&gt;&lt;/p&gt;&lt;p style="\"text-align:" justify;="" \"=""&gt;&lt;span style="\"font-size:" 13px;="" font-family:="" arial;="" text-decoration-skip-ink:="" none;\"=""&gt;Angkor Wat combines two basic plans of Khmer temple architecture: the temple-mountain and the later galleried temple. It is designed to represent Mount Meru, home of the devas in Hindu mythology: within a moat and an outer wall 3.6 kilometres (2.2 mi) long are three rectangular galleries, each raised above the next. At the centre of the temple stands a quincunx of towers. Unlike most Angkorian temples, Angkor Wat is oriented to the west; scholars are divided as to the significance of this. The temple is admired for the grandeur and harmony of the architecture, its extensive bas-reliefs, and for the numerous devatas adorning its walls.&lt;/span&gt;&lt;/p&gt;
  </code></pre>
  
  <blockquote>
    <p>You can test this string by copy and paste the whole text into <a href="https://regex101.com/" rel="noreferrer">this website</a> because I want to find the correct Regex that can remove all CSS style.</p>
  </blockquote>
  
  <p>I want the regex that can work like this <a href="https://html-cleaner.com/" rel="noreferrer">Useful HTML Cleaner Website</a></p>
  
  <p>This is before cleaning the HTML:</p>
  
  <p><a href="https://i.stack.imgur.com/ktwTl.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ktwTl.png" alt="Before cleaning HTML"></a></p>
  
  <p>And this is after cleaning the HTML: </p>
  
  <p><a href="https://i.stack.imgur.com/jwDnq.png" rel="noreferrer"><img src="https://i.stack.imgur.com/jwDnq.png" alt="After Cleaning HTML"></a></p>
  
  <p><strong>These website can clean all HTML attribute and it doesn't care if those attribute is in the wrong format</strong></p>
  
  <p>I found many Regex on the website that can clean the html attribute but it's not working with my situation: Here are some regex: </p>
  
  <ul>
  <li><code>&lt;[^&gt;]+((style|class)="[^"]*")[^&gt;]*&gt;</code></li>
  <li><code>&lt;\s*([a-z][a-z0-9]*)\s.*?&gt;</code></li>
  <li><code>style=\"([^\"]*)\"</code></li>
  <li><code>style="(.*?)"</code></li>
  <li><code>&lt;\\s*([a-z][a-z0-9]*)\\s.*?&gt;</code></li>
  </ul>
  
  <p><strong><em>EDIT</em></strong>
  here is a useful function that can remove the style from Tobi:</p>
  
  <pre><code>let regex = try! NSRegularExpression(pattern: "style=\"([^\"]*)\"", options: .caseInsensitive)
          let range = NSMakeRange(0, html.characters.count)
          let modString = regex.stringByReplacingMatches(in: html, options: [], range: range, withTemplate: "")
  </code></pre>
  
  <p>And the result of this regex is still like this: </p>
  
  <pre><code>&lt;p text-align:" justify;="" \"=""&gt;&lt;span font-size:" 13px;="" font-family:="" arial;="" text-decoration-skip-ink:="" none;\"=""&gt;&lt;b&gt;&lt;span &gt;Angkor Wat&lt;/span&gt;&lt;/b&gt; is a temple complex in Cambodia and the largest religious monument in the world, on a site measuring 162.6 hectares (1,626,000 m2; 402 acres). It was originally constructed as a Hindu temple dedicated to the god Vishnu for the Khmer Empire, gradually transforming into a Buddhist temple towards the end of the 12th century. It was built by the Khmer King Suryavarman II in the early 12th century in Yaśodharapura, the capital of the Khmer Empire, as his state temple and eventual mausoleum. Breaking from the Shaiva tradition of previous kings, Angkor Wat was instead dedicated to Vishnu. As the best-preserved temple at the site, it is the only one to have remained a significant religious centre since its foundation. The temple is at the top of the high classical style of Khmer architecture. It has become a symbol of Cambodia, appearing on its national flag, and it is the country\'s prime attraction for visitors.&lt;/span&gt;&lt;/p&gt;&lt;p text-align:" justify;="" \"=""&gt;&lt;span font-size:" 13px;="" font-family:="" arial;="" text-decoration-skip-ink:="" none;\"=""&gt;Angkor Wat combines two basic plans of Khmer temple architecture: the temple-mountain and the later galleried temple. It is designed to represent Mount Meru, home of the devas in Hindu mythology: within a moat and an outer wall 3.6 kilometres (2.2 mi) long are three rectangular galleries, each raised above the next. At the centre of the temple stands a quincunx of towers. Unlike most Angkorian temples, Angkor Wat is oriented to the west; scholars are divided as to the significance of this. The temple is admired for the grandeur and harmony of the architecture, its extensive bas-reliefs, and for the numerous devatas adorning its walls.&lt;/span&gt;&lt;/p&gt;
  </code></pre>
  
  <p>Please use this <a href="https://regex101.com/" rel="noreferrer">Website</a> to test my given string </p>
  
  <p><a href="https://i.stack.imgur.com/PdcLB.png" rel="noreferrer"><img src="https://i.stack.imgur.com/PdcLB.png" alt="This regex can clear the CSS (style=&quot; &quot;) only"></a></p>
  
  <p><strong>This regex can clear only the style that in format <em>style=" "</em> only</strong></p>