- The first Regular Expression Library on the Web!

Please support RegExLib Sponsors


Expressions by User

   Displaying page 1 of 1 pages; Items 1 to 1
Title Test Details Pattern Title
<\*?font # Match start of Font Tag (?(?=[^>]+color.*>) #IF/THEN lookahead color in tag (.*?color\s*?[=|:]\s*?) # IF found THEN move ahead ('+\#*?[\w\s]*'+ # CAPTURE ColorName/Hex |"+\#*?[\w\s]*"+ # single or double |\#*\w*\b) # or no quotes .*?> # & move to end of tag |.*?> # ELSE move to end of Tag ) # Close the If/Then lookahead # Use Multiline and IgnoreCase # Replace the matches from RE with MatchEvaluator below: # if m.Groups(1).Value<>"" then # Return "<font color=" & m.Groups(1).Value & ">" # else # Return "<font>" # end if
This RE and MatchEvaluator will remove everything from inside HTML font tags EXCEPT the color declaration. (For ex: allow users to upload HTML content to site without their font tags overridding the font styles set in the CSS, except for the ability to change the font color for special emphasis.) This works with color declarations using single quotes, double quotes, no quotes, color-names (red, black), Hex colors (#669933), and inline Style declarations inside a font tag. Does not work with inline Style declarations inside other tags like DIV, SPAN, or P (although it could be expanded to include those as well).
<font size=5 color=black face=Arial> | <font style="font-family:arial;color:red"&
<DIV style="font-family:arial;color:red"> | <SPAN style="color:red">
Author Rating: Not yet rated. Cheri Verdend
   Displaying page 1 of 1 pages; Items 1 to 1

Copyright © 2001-2018, | ASP.NET Tutorials