加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

使用正则表达式去除html中的标签元素以及js和css脚本和样式

发布时间:2020-12-14 00:56:43 所属栏目:百科 来源:网络整理
导读:ww.dotdy.com/ Java代码 public static void main(String[]args){ Stringstr=readFile( new File( "D:workspaceizbra_frontWebRootaaaa.java" )); //先过滤script标签 Stringreg_tag= "[s]*?#t#[^]*?[sS]*?[s]*?/[s]*?#t#[s]*?" .re

ww.dotdy.com/


Java代码
  1. publicstaticvoidmain(String[]args){
  2. Stringstr=readFile(newFile("D:workspaceizbra_frontWebRootaaaa.java"));
  3. //先过滤script标签
  4. Stringreg_tag="<[s]*?#t#[^>]*?>[sS]*?<[s]*?/[s]*?#t#[s]*?>".replace("#t#","script");
  5. str=Pattern.compile(reg_tag,Pattern.CASE_INSENSITIVE).matcher(str).replaceAll("");
  6. //再过滤hmtl标签
  7. reg_tag="<[^>]+>";
  8. reg_tag="<[sS]*?>";
  9. str=str.replaceAll("","");
  10. str=str.replaceAll("n{1,}","#");
  11. str=str.startsWith("#")?str.substring(1):str;
  12. str=str.endsWith("#")?str.substring(0,str.length()- System.out.println("数量=="+str.split("#").length);
  13. str=str.replaceAll("#","n");
  14. System.out.println(str);
  15. }
  16. staticStringreadFile(Filefile){
  17. StringBuildersb=newStringBuilder();
  18. try{
  19. BufferedReaderbr=newBufferedReader(newInputStreamReader(newFileInputStream(file),"UTF-8"));
  20. Stringline=null;
  21. while((line=br.readLine())!=null){
  22. if("添加".equals(line))
  23. continue;
  24. sb.append(line+"n");
  25. br.close();
  26. }catch(Exceptione){
  27. e.printStackTrace();
  28. returnsb.toString();
  29. }


Java代码
  1. voidmain(String[]args){
  2. newFile("D:workspaceizbra_frontWebRootaaaa.java"));
  3. //先过滤script标签
  4. "script");
  5. "");
  6. //再过滤hmtl标签
  7. reg_tag="<[^>]+>";
  8. reg_tag="<[sS]*?>";
  9. "");
  10. "#");
  11. 1):str;
  12. System.out.println("数量=="+str.split("#").length);
  13. "n");
  14. System.out.println(str);
  15. }
  16. staticStringreadFile(Filefile){
  17. newStringBuilder();
  18. try{
  19. "UTF-8"));
  20. null;
  21. null){
  22. if("添加".equals(line))
  23. continue;
  24. sb.append(line+"n");
  25. br.close();
  26. catch(Exceptione){
  27. e.printStackTrace();
  28. returnsb.toString();
  29. }


伦理片http://www.dotdy.com/

}


影音先锋电影http://www.iskdy .com/




Java代码
  1. voidmain(String[]args){
  2. newFile("D:workspaceizbra_frontWebRootaaaa.java"));
  3. //先过滤script标签
  4. "script");
  5. "");
  6. //再过滤hmtl标签
  7. reg_tag="<[^>]+>";
  8. reg_tag="<[sS]*?>";
  9. "");
  10. "#");
  11. 1):str;
  12. System.out.println("数量=="+str.split("#").length);
  13. "n");
  14. System.out.println(str);
  15. }
  16. staticStringreadFile(Filefile){
  17. newStringBuilder();
  18. try{
  19. "UTF-8"));
  20. null;
  21. null){
  22. if("添加".equals(line))
  23. continue;
  24. sb.append(line+"n");
  25. br.close();
  26. catch(Exceptione){
  27. e.printStackTrace();
  28. returnsb.toString();
  29. }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读