Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何删除字符串中的html标记?_Java_Html - Fatal编程技术网

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

Java 如何删除字符串中的html标记?,java,html,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'>dat

当我搜索关键字“数据””时,我得到了数字图书馆中的一篇论文:

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
许多组织经常未充分利用其现有的数据仓库。在本文中,我们提出了一种从公司数据仓库中获取更多信息的方法,而不需要部署其他软件系统的复杂性和缺点。关联规则挖掘捕获数据中的共生模式,吸引了数据仓库研究人员和从业者的大量努力。不幸的是,大多数数据挖掘工具最多与数据仓库存储库松散耦合。此外,这些工具通常只能在数据仓库的主事实表中找到关联规则(因此忽略了星型模式中信息丰富的维度),并且不容易应用于数据仓库中常见的非事务级数据
如何删除所有标记
,但仍保留keywod数据,以使其具有类似这样的轨迹:

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

公共静态字符串条带\u标记(字符串文本、字符串允许标记){
String[]tag_list=allowedTags.split(“,”);
数组。排序(标记列表);
最终模式p=Pattern.compile(“]*)\\\\s*[^>]*>”,
模式(不区分大小写);
匹配器m=p.Matcher(文本);
StringBuffer out=新的StringBuffer();
int-lastPos=0;
while(m.find()){
字符串标记=m.group(1);
//如果不允许标记:跳过它
if(Arrays.binarySearch(标记列表,标记)<0){
out.append(text.substring(lastPos,m.start()).append(“”);
}否则{
out.append(text.substring(lastPos,m.end());
}
lastPos=m.end();
}
如果(lastPos>0){
out.append(text.substring(lastPos));
return out.toString().trim();
}否则{
返回文本;
}
}

是否总是
?您可以使用简单的字符串替换或正则表达式。如果可以出现任何类型的HTML,我建议您使用解析器而不是正则表达式。如果你想要一个好的解析器,请查看这个wiki…re:regex和HTML。。。马尔科:不,这是一个示例,通过关键字搜索是的,是的,我知道正则表达式和HTML不是一对很好的组合,至少有一个问题是关于使用C#剥离HTML中的标记的,答案总是HTMLAGILITIPACK。这就是为什么我问这是否是一个单一的事件,其中一个
String.Replace
就足够了。
  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;
      }
  }