简体   繁体   中英

Flex 4.5 - How do you strip tags?

在Flex 4.5 / 4.6中,如何从字符串中剥离(HTML)标签?

I don't think there's an inbuilt function to strip the tags like in php.

However, you could use a regular expression to remove all text between < and >

var r:RegExp=/<\/??.*?\/??>/g;

I gotta run now, but if you could follow my line of thought:

While the string tests positive for the regexp, replace the occurrence with an empty string

That should remove all occurrences of this type:

<tag>
<tag />
</tag>

EDIT

var h:String="<html><head><title>Hello World</title></head><body><h1>Hello</h1>Hey there, what's new?</body></html>";
var r:RegExp=/<\/??.*?\/??>/s; //s=dotall to match . to newline also


while(r.test(h)) {
    h=h.replace(r, ""); //Remember, strings are immutable, so you h.replace will not change the value of h, so you need to reassign the return to h
}

trace(h);

OUTPUT:

Hello WorldHelloHey there, what's new?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM