【问题标题】:Flex 4.5 - How do you strip tags?Flex 4.5 - 你如何剥离标签?
【发布时间】:2023-03-25 09:25:01
【问题描述】:

如何在 Flex 4.5 / 4.6 中从字符串中去除 (HTML) 标签?

【问题讨论】:

  • 用户正则表达式! Google it google.com/… 然后你只需要将 Regex 转换为 ActionScript。
  • @JamesTomasino 实际上下面提供的正则表达式与您提到的链接不同。
  • 4.6 预发布版已经发布,不久将公开发布
  • @JamesTomasino 您链接的示例似乎仅适用于 div 而不是 <b>和其他人?

标签: apache-flex actionscript flex4 flex4.5


【解决方案1】:

我认为没有像 php 中那样去除标签的内置函数。

但是,您可以使用正则表达式删除 &lt;&gt; 之间的所有文本

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 WorldHello,你好,有什么新消息?

【讨论】:

  • 这实际上返回一个空字符串...stringToParse.replace(r,"") ...你怎么让它只是剥离标签而不剥离一切?
  • 尝试转义 &lt;&gt;,好吗?
  • 我一定是疯了,但是你转义括号的意思是:var r:RegExp=/\&lt;\/??.*?\/??\&gt;/g;
  • 不,我没有。正如我在回答中所写,我needed to run,所以我无法测试我的代码并写出完整的答案
  • 啊,你看,匹配只替换一次,所以需要替换多次
猜你喜欢
  • 2014-03-16
  • 1970-01-01
  • 2017-04-25
  • 2013-07-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-27
相关资源
最近更新 更多