x Did you like it? Well, then please consider making a donation :)

Remove "Style" attribute from HTML tags

Remove all "style" attributes from HTML text.

Tags: #css, #html, #match.replace, #remove, #replace, #style, #web. Views: 18853. admin, 8/12/2015
Link 1: http://www.systemtextregularexpressions.com/r20/remove-style-attribute-from-html-tags
Link 2: http://www.systemtextregularexpressions.com/r20 (short)


Length: 0b, Line: 1, Cursor: 0

RegexOptions

IsMatch=true

Result

<h1 class="h1class"><span>abc</span></h1> <span>12313</span> <h2 class="dwdwd">text<span>style</span></h2> <span >adasd</span>

Share (without adding to database):

Source code

0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
//.NET Regex.Replace Online Tester: www.systemtextregularexpressions.com

//Namespace
using System.Text.RegularExpressions;

//Regex Pattern
string pattern = @"<([^>]*)(\sstyle="".+?""(\s|))(.*?)>";

//Regex example #1
Regex r = new Regex(@"<([^>]*)(\sstyle="".+?""(\s|))(.*?)>");
string result1 = r.Replace("input text", "replacement text");

//Regex example #2
string result2 = Regex.Replace("input text", @"<([^>]*)(\sstyle="".+?""(\s|))(.*?)>", "replacement text");
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
'.NET Regex.Replace Online Tester: www.systemtextregularexpressions.com

'Namespace
Imports System.Text.RegularExpressions

'Regex Pattern
Dim pattern As String = "<([^>]*)(\sstyle="".+?""(\s|))(.*?)>"

'Regex example #1
Dim r As Regex = New Regex("<([^>]*)(\sstyle="".+?""(\s|))(.*?)>")
Dim result1 As String = r.Replace("input text", "replacement text")

'Regex example #2
Dim result2 As String = Regex.Replace("input text", "<([^>]*)(\sstyle="".+?""(\s|))(.*?)>", "replacement text")