【问题标题】:Stripe HTML tags in Google Apps Script在 Google Apps 脚本中条带化 HTML 标记
【发布时间】:2016-12-16 18:16:27
【问题描述】:

我正在寻找从 Google Apps 脚本中的内容中删除 HTML 标记的快速方法。

现在我正在使用这些函数来解析 HTML:

function getTextFromHtml(body) {
  return getTextFromNode(Xml.parse(body, true).getElement());
}

function getTextFromNode(x) {
 switch(x.toString()) {
  case 'XmlText': return x.toXmlString();
  case 'XmlElement': return x.getNodes().map(getTextFromNode).join('');
  default: return '';
 }
}

但是对于长 HTML 来说,这种方式效率太低了。

示例 HTML 内容:http://pastebin.com/FmB4hvN2

有什么想法吗?

【问题讨论】:

    标签: javascript html google-apps-script google-apps


    【解决方案1】:

    这将从输入中删除所有标签。

     var text = html.replace(/<[^>]+>/g, "");
    

    【讨论】:

      【解决方案2】:

      如果你要替换的内容总是用包裹,你可以这样做

      Regex rgx = new Regex(someString);
      string result = rgx.Replace("<[^>]*>", "");
      

      【讨论】:

        猜你喜欢
        • 2023-04-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-08-23
        • 1970-01-01
        相关资源
        最近更新 更多