PDA

View Full Version : replace character for every unicode char


aEr_aEr
11-21-2002, 08:44 AM
hi,

i want to maken a filter that replaces 2 or more font tags with one, I want the attributes of the innerFonttag to replace the attributes of the outerFonttag

example:

<font color=#ff6677 size=2><font size=3 face=arial>fadsf</font></font>


this i want to replace with


<font color=#ff6677 size=3 face=arial>fadsf</font>


but between the <font> and the </font> almost every character is possible how do i filter that. And how can i build replace string.

I've tried a couple of things and came up with something like this

tekst = tekst.replace(/<font\s[\w:\"\';\#]*><font\s[\w:\"\';\#]*>[\w]*</font></font>/ig,"");

but this doesn't work because it clears the font tags and not every character between the font-tags is seen only alphanumeric character and underscore.

does anyone have a id how to do this correct

Roy Sinclair
11-21-2002, 03:49 PM
Since Javascript isn't a tool where you can read and write files I don't think it's the tool for filtering HTML.

I don't think you need to develop a new tool either, take a look at HTML Tidy (http://tidy.sourceforge.net/). It won't do exactly what you asked for because it's cleanup discards the deprecated (that means officially discouraged and eventually will be eliminated) tags like FONT and replaces them with CSS styles but it's a really good tool for HTML cleanup (you can even use it to clean up the ugly HTML that's generated by MS Office products).