如何删除字符串中的html标签?

时间:2010-10-20 03:43:24

标签: java html

当我搜索关键字“数据”时,我会在数字图书馆中获取纸张:

Many organizations often underutilize their existing <span class='snippet'>data</span> warehouses. In this paper, we suggest a way of acquiring more information from corporate <span class='snippet'>data</span> warehouses without the complications and drawbacks of deploying additional software systems. Association-rule mining, which captures co-occurrence patterns within <span class='snippet'>data</span>, has attracted considerable efforts from <span class='snippet'>data</span> warehousing researchers and practitioners alike. Unfortunately, most <span class='snippet'>data</span> mining tools are loosely coupled, at best, with the <span class='snippet'>data</span> warehouse repository. Furthermore, these tools can often find association rules only within the main fact table of the <span class='snippet'>data</span> warehouse (thus ignoring the information-rich dimensions of the star schema) and are not easily applied on non-transaction level <span class='snippet'>data</span> often found in <span class='snippet'>data</span> warehouses

如何删除所有代码<span class='snippet'>..</span>,但仍然保持keywod数据具有类似的结果:

许多组织经常未充分利用其现有的数据仓库。在本文中,我们建议一种从企业数据仓库获取更多信息的方法,而没有部署其他软件系统的复杂性和缺点。关联规则挖掘捕获数据中的共现模式,吸引了数据仓库研究人员和从业人员的相当大的努力。不幸的是,大多数数据挖掘工具充其量只与数据仓库存储库耦合。此外,这些工具通常只能在数据仓库的主要事实表中找到关联规则(因此忽略了星型模式的信息丰富的维度),并且不容易应用于数据仓库中常见的非事务级数据

1 个答案:

答案 0 :(得分:2)

strip_tags()是你的朋友。 Code kindly copied from here

  public static String strip_tags(String text, String allowedTags) {
      String[] tag_list = allowedTags.split(",");
      Arrays.sort(tag_list);

      final Pattern p = Pattern.compile("<[/!]?([^\\\\s>]*)\\\\s*[^>]*>",
              Pattern.CASE_INSENSITIVE);
      Matcher m = p.matcher(text);

      StringBuffer out = new StringBuffer();
      int lastPos = 0;
      while (m.find()) {
          String tag = m.group(1);
          // if tag not allowed: skip it
          if (Arrays.binarySearch(tag_list, tag) < 0) {
              out.append(text.substring(lastPos, m.start())).append(" ");

          } else {
              out.append(text.substring(lastPos, m.end()));
          }
          lastPos = m.end();
      }
      if (lastPos > 0) {
          out.append(text.substring(lastPos));
          return out.toString().trim();
      } else {
          return text;
      }
  }