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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Unnecessary Spaces in XHTML Attribute
Expression
(?<=(,|;|:))\s(?=((?:(?!<).)*>))
Description
Needing a way to shrink HTML based email to the smallest amount of characters, we wanted to remove any extra unnecessary white space characters in attributes such as style. This finds any space with a proceeding comma, semi-colon, or colon, and then checks with a lookahead for the closing > with a negative lookbehind to make sure that a < opening does not exist. The secondary trailing look behind is done to make sure that it does not change any content contained in the element.
Matches
<table width="750px" cellpadding="0" cellspacing="0" style="font-family: Arial , Helvetica , Sans-Serif ; font-size: 10pt;">
Non-Matches
<td>1, 2, 3</td>
Author Rating: The rating for this expression. Andrew Gruden
Source
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-2025, RegexAdvice.com | ASP.NET Tutorials