Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Feb 2009
    Location
    Worcester
    Posts
    172
    Thanks
    13
    Thanked 6 Times in 6 Posts

    Escape an empty tag in a string?

    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:

    Code:
    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!

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    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:
    Code:
    // these are not tested
    txtVar = txtVar.replace(/<\/?li[^>]*>/gi, ""); // remove
    
    txtVar = txtVar.replace(/<(\/?li[^>]*)>/gi, "&lt;$1&gt;"); // escape?

  • #3
    Regular Coder
    Join Date
    Feb 2009
    Location
    Worcester
    Posts
    172
    Thanks
    13
    Thanked 6 Times in 6 Posts
    Hi,

    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:
    Code:
    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 )
    Last edited by loki421; 07-17-2010 at 06:33 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •