RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Capture bgcolor attribute for replacing with style attribute
Expression
<.*\b(bgcolor\s*=\s*[\"|\']*(\#\w{6})[\"|\']*).*>
Description
Variable 1 = "complete attribute and value". Variable 2 = "attribute value only". For meeting compliance with W3C AA rules, I've been using this in a simple HTML parser to convert certain background tags from the deprecated 'bgcolor' attribute to now using a 'style=background:' and the passed colour. This had to be only on hexadecimal values for my current needs. Later modifications : 1. Only for certain tags (eg. td,tr,table). 2. If matching an opening apostrophe/quotation mark, only capture variable if there is a closing one.
Matches
table bgcolor="#A3A3A3" | table bgcolor= #A3A3A3" | td bgcolor= #A3A3A3 | td bgcolor=#A3A3A3 alt="somethingelse"
Non-Matches
tr bgcolor="" test | tablebgcolor="#A3A3A3" | table bgcolor="test2" | td bgcolor="red" | td bgcolor="#$%skis"
Author Rating: The rating for this expression. Tom Meier
Source Tom Meier
Your Rating
Bad Good

Enter New Comment

Title

Name

Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Copyright © 2001-2024, RegexAdvice.com | ASP.NET Tutorials