View Full Version : Escape an empty tag in a string?

06-29-2010, 12:51 AM
Hi guys,

I am trying to escape an empty tag in a string.

I have a bizzare error when I pass a RichTextEditor HTML text to a string, if I add a line break before I start the bullet points, it adds an empty <li></li> which I would like to remove.

Here's the code I'm using to escape the rest of the formating:

private function scanTxt():void{
txtVar = richtexteditor.htmlText;
var pattern:RegExp = /<TEXTFORMAT.*?>/g;
txtVar = txtVar.replace(pattern, "");
pattern = /<FONT.*?>/g;
txtVar = txtVar.replace(pattern, "");
pattern = /<\/FONT.*?>/g;
txtVar = txtVar.replace(pattern, "");
pattern = /<\/TEXTFORMAT.*?>/g;
txtVar = txtVar.replace(pattern, "");
// this is where i'm stuck, i want it to look for <li></li> (an empty list item tag)
pattern = /<\/LI><\//LI>/g;

Does anyone know what the correct syntax is to look for an empty tag and escape it?

Or, is there something I'm doing wrong to get the extra <li> at the beginning of any bullet lists i insert?

Any help would be gratefully received!

Thanks in advance all! :)

07-17-2010, 06:11 PM
You've probably solved this by now, but if not: What did you mean by escape? If you want to remove it like your previous examples you would do this:

// these are not tested
txtVar = txtVar.replace(/<\/?li[^>]*>/gi, ""); // remove

txtVar = txtVar.replace(/<(\/?li[^>]*)>/gi, "&lt;$1&gt;"); // escape?

07-17-2010, 06:30 PM

Yes, sorry, I did manage to work it out in the end. I wanted to remove the blank li tag, should have been a bit clearer I guess.

I used:

var txt:String = new String();
txt = richtexteditortxt.htmlText;
var pattern:RegExp = /<LI><\/LI>/g;
txt = txt.replace(pattern, "");

Think it's pretty much the same as you posted, but thanks anyway! :)

(Edited coz I'm an idiot :p)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum