sharmacal
sharmacal

Reputation: 457

removing html tag in as3

I have an html text as

 <span>
    <span class="embed_photo_div" dir="ltr">
        <span class="embed_photo">
            <img src="image.jpg">
        </span>
    </span>
  </span>

I am needing the final output as <span> </span> ie the span tag with class embed_photo_div should get removed.

What is the best approach to remove certain sections of htmltext in as3?

Upvotes: 0

Views: 925

Answers (2)

Ilya Zaytsev
Ilya Zaytsev

Reputation: 1055

You will can use RegEx match and replace, your pattern:

 /<[^<]?span.*class="embed_photo".*>[\w<\s=\".>\r\n\s\t]*</\s?span\s?>/g

Link for online example: http://regexr.com?33tnl

Edited: don't forget escaping characters "/". Added example

var x:XML =
    <span>
       <span class="embed_photo_div" dir="ltr">
           <span class="embed_photo">
               <img src="image.jpg"/>
           </span>
       </span>
     </span>;

var str:String = x.toXMLString();

var pattern :RegExp = new RegExp( /<span class="embed_photo"[\r\n\t\s\w=".<>]*[\/>]*[\r\n\t\s]*<\/span>/g );

var output:String = str.replace(pattern, "<span> </span>");

trace(output);

Upvotes: 1

mitim
mitim

Reputation: 3201

What I've done in the past is treat it as xml (after all html is xml) and parse it that way to get at what I want.

Upvotes: 1

Related Questions