如何从Flex 4.5 / 4.6中的String中剥离(HTML)标记?
答案 0 :(得分:0)
我不认为有一个内置函数来剥离像php中的标记。
但是,您可以使用正则表达式删除<
和>
之间的所有文字
var r:RegExp=/<\/??.*?\/??>/g;
我现在要跑了,但如果你能按照我的想法行事:
虽然字符串对正则表达式测试为正,但用空字符串替换该字符串
这应该删除所有此类型:
<tag>
<tag />
</tag>
修改强>
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);
输出:
Hello WorldHelloHey那里有什么新东西?