java去除Html所有标签、空格以及空白,style标签以及script标签

2018-02-01 15:45:21

java和php类似,根据正则进行去除,代码如下

/**
 * 替换掉HTML标签方法升级版
 */
public static String delHTMLTag(String htmlStr){
   String regEx_script="<script[^>]*?>[\\s\\S]*?<\\/script>"; //定义script的正则表达式
   String regEx_style="<style[^>]*?>[\\s\\S]*?<\\/style>"; //定义style的正则表达式
   String regEx_html="<[^>]+>"; //定义HTML标签的正则表达式

   Pattern p_script= Pattern.compile(regEx_script,Pattern.CASE_INSENSITIVE);
   Matcher m_script=p_script.matcher(htmlStr);
   htmlStr=m_script.replaceAll(""); //过滤script标签

   Pattern p_style=Pattern.compile(regEx_style,Pattern.CASE_INSENSITIVE);
   Matcher m_style=p_style.matcher(htmlStr);
   htmlStr=m_style.replaceAll(""); //过滤style标签

   Pattern p_html=Pattern.compile(regEx_html,Pattern.CASE_INSENSITIVE);
   Matcher m_html=p_html.matcher(htmlStr);
   htmlStr=m_html.replaceAll(""); //过滤html标签

   return htmlStr.trim(); //返回文本字符串
}

/**
 * 字符串去掉所有空格和回车
 */
public static String replaceBlank(String str) {
   String dest = "";
   if (str!=null) {
      Pattern p = Pattern.compile("\\s*|\t|\r|\n");
      Matcher m = p.matcher(str);
      dest = m.replaceAll("");
   }
   return dest;
}


  • 2019-12-17 11:58:55

    FFmpeg文章目录

    seek ffmpeg # How to seek in mp4/mkv/ts/flv ffmpeg # flags &= ~AVSEEK_FLAG_BACKWARD ffmpeg # AVSEEK_FLAG concat ffmpeg # concat 连接两个视频 ffmpeg # -f concat -i mylist.txt ffmpeg # concat详解+音画同步策略 截图

  • 2019-12-18 23:26:00

    FFMPEG命令记录

    ffmpeg,拼接两个音频,剪切音频片段,多个音频混音,剪切一段MP4并转换成gif,改变音量大小,音频淡入淡出,音频格式处理

  • 2019-12-19 00:04:44

    ffmpeg concat video and mix audio

    在ffmpeg中,官网给出两种连接媒体文件(音频、视频、etc..)的解决方案。 the concat "demuxer" the concat "protocol" 对比而言, demuxer更加灵活一些,需要媒体文件是属于相同的编解码器,但是可以属于不同的容器格式(mp3,wav, mp4, mov, etc..). 而protocol只适用于少数集中容器格式。

  • 2019-12-19 00:16:30

    android采用FFmpeg实现音频混合与拼接剪切

    接触FFmpeg有一段时间了,它是音视频开发的开源库,几乎其他所有播放器、直播平台都基于FFmpeg进行二次开发。本篇文章来总结下采用FFmpeg进行音频处理:音频混合、音频剪切、音频拼接与音频转码。

  • 2019-12-19 15:01:58

    spring boot 在Linux下服务启动报错Unable to find Java

    将 Spring boot 安装为 Linux 服务启动,后输入 service myapp start 报错 Unable to find Java ,但是使用 java -jar myapp.jar 启动成功。不知道为啥引起的,经过百度找到下面这个解决方法和我的情况一样,终于把问题解决