Enviar búsqueda
Cargar
Java正则表达式过滤html标签
•
Descargar como DOCX, PDF
•
0 recomendaciones
•
678 vistas
T
tonyhuang2008
Seguir
ddddddd
Leer menos
Leer más
Tecnología
Entretenimiento y humor
Denunciar
Compartir
Denunciar
Compartir
1 de 6
Descargar ahora
Recomendados
Clang-tidy: путешествие внутрь AST C++
Clang-tidy: путешествие внутрь AST C++
corehard_by
Шаблоны проектирования 2
Шаблоны проектирования 2
Constantin Kichinsky
Acceleration or equilibrium practice quiz
Acceleration or equilibrium practice quiz
Varitsara
Buy 1 get the set central credit cards
Buy 1 get the set central credit cards
Jaruwan Pongjaruwat
Peoples and empires
Peoples and empires
Ernesto Medina
บทที่7
บทที่7
ยัยบ้อง ตาบร้า
สื่อและแหล่งการเรียนรู้
สื่อและแหล่งการเรียนรู้
ยัยบ้อง ตาบร้า
Press Review February
Press Review February
Jaruwan Pongjaruwat
Recomendados
Clang-tidy: путешествие внутрь AST C++
Clang-tidy: путешествие внутрь AST C++
corehard_by
Шаблоны проектирования 2
Шаблоны проектирования 2
Constantin Kichinsky
Acceleration or equilibrium practice quiz
Acceleration or equilibrium practice quiz
Varitsara
Buy 1 get the set central credit cards
Buy 1 get the set central credit cards
Jaruwan Pongjaruwat
Peoples and empires
Peoples and empires
Ernesto Medina
บทที่7
บทที่7
ยัยบ้อง ตาบร้า
สื่อและแหล่งการเรียนรู้
สื่อและแหล่งการเรียนรู้
ยัยบ้อง ตาบร้า
Press Review February
Press Review February
Jaruwan Pongjaruwat
Attapol panyatontrakool
Attapol panyatontrakool
You Cool
Attapol panyatontrakool
Attapol panyatontrakool
You Cool
My pdf
My pdf
Jaruwan Pongjaruwat
งานนำเสนอ2
งานนำเสนอ2
ยัยบ้อง ตาบร้า
My picture
My picture
suwanan_rattanasila
Attapol panyatontrakool
Attapol panyatontrakool
You Cool
Newsletter 06 2011
Newsletter 06 2011
Jaruwan Pongjaruwat
บทที่ 8 การวัดประเมินผลการเรียนรู้
บทที่ 8 การวัดประเมินผลการเรียนรู้
ยัยบ้อง ตาบร้า
New York City
New York City
Ernesto Medina
Little Ice Age - Big Problems
Little Ice Age - Big Problems
Ernesto Medina
Pitchbook
Pitchbook
Jaruwan Pongjaruwat
Más contenido relacionado
Destacado
Attapol panyatontrakool
Attapol panyatontrakool
You Cool
Attapol panyatontrakool
Attapol panyatontrakool
You Cool
My pdf
My pdf
Jaruwan Pongjaruwat
งานนำเสนอ2
งานนำเสนอ2
ยัยบ้อง ตาบร้า
My picture
My picture
suwanan_rattanasila
Attapol panyatontrakool
Attapol panyatontrakool
You Cool
Newsletter 06 2011
Newsletter 06 2011
Jaruwan Pongjaruwat
บทที่ 8 การวัดประเมินผลการเรียนรู้
บทที่ 8 การวัดประเมินผลการเรียนรู้
ยัยบ้อง ตาบร้า
New York City
New York City
Ernesto Medina
Little Ice Age - Big Problems
Little Ice Age - Big Problems
Ernesto Medina
Pitchbook
Pitchbook
Jaruwan Pongjaruwat
Destacado
(11)
Attapol panyatontrakool
Attapol panyatontrakool
Attapol panyatontrakool
Attapol panyatontrakool
My pdf
My pdf
งานนำเสนอ2
งานนำเสนอ2
My picture
My picture
Attapol panyatontrakool
Attapol panyatontrakool
Newsletter 06 2011
Newsletter 06 2011
บทที่ 8 การวัดประเมินผลการเรียนรู้
บทที่ 8 การวัดประเมินผลการเรียนรู้
New York City
New York City
Little Ice Age - Big Problems
Little Ice Age - Big Problems
Pitchbook
Pitchbook
Java正则表达式过滤html标签
1.
import java.util.regex.Matcher;<br />import
java.util.regex.Pattern;<br />/**<br /> * <p><br /> * Title: HTML相关的正则表达式工具类<br /> * </p><br /> * <p><br /> * Description: 包括过滤HTML标记,转换HTML标记,替换特定HTML标记<br /> * </p><br /> * <p><br /> * Copyright: Copyright (c) 2006<br /> * </p><br /> * <br /> * @author hejian<br /> * @version 1.0<br /> * @createtime 2006-10-16<br /> */<br />public class HtmlRegexpUtil {<br />private final static String regxpForHtml = quot; <([^>]*)>quot; ; // 过滤所有以<开头以>结尾的标签<br />private final static String regxpForImgTag = quot; <s*imgs+([^>]*)s*>quot; ; // 找出IMG标签<br />private final static String regxpForImaTagSrcAttrib = quot; src=" ([^" ]+)" quot; ; // 找出IMG标签的SRC属性<br />/**<br /> * <br /> */<br />public HtmlRegexpUtil() {<br />// TODO Auto-generated constructor stub<br />}<br />/**<br /> * <br /> * 基本功能:替换标记以正常显示<br /> * <p><br /> * <br /> * @param input<br /> * @return String<br /> */<br />public String replaceTag(String input) {<br />if (!hasSpecialChars(input)) {<br />return input;<br />}<br />StringBuffer filtered = new StringBuffer(input.length());<br />char c;<br />for (int i = 0; i <= input.length() - 1; i++) {<br />c = input.charAt(i);<br />switch (c) {<br />case '<':<br />filtered.append(quot; <quot; );<br />break;<br />case '>':<br />filtered.append(quot; >quot; );<br />break;<br />case 'quot; ':<br />filtered.append(quot; "quot; );<br />break;<br />case '&':<br />filtered.append(quot; &quot; );<br />break;<br />default:<br />filtered.append(c);<br />}<br />}<br />return (filtered.toString());<br />}<br />/**<br /> * <br /> * 基本功能:判断标记是否存在<br /> * <p><br /> * <br /> * @param input<br /> * @return boolean<br /> */<br />public boolean hasSpecialChars(String input) {<br />boolean flag = false;<br />if ((input != null) && (input.length() > 0)) {<br />char c;<br />for (int i = 0; i <= input.length() - 1; i++) {<br />c = input.charAt(i);<br />switch (c) {<br />case '>':<br />flag = true;<br />break;<br />case '<':<br />flag = true;<br />break;<br />case 'quot; ':<br />flag = true;<br />break;<br />case '&':<br />flag = true;<br />break;<br />}<br />}<br />}<br />return flag;<br />}<br />/**<br /> * <br /> * 基本功能:过滤所有以quot; <quot; 开头以quot; >quot; 结尾的标签<br /> * <p><br /> * <br /> * @param str<br /> * @return String<br /> */<br />public static String filterHtml(String str) {<br />Pattern pattern = Pattern.compile(regxpForHtml);<br />Matcher matcher = pattern.matcher(str);<br />StringBuffer sb = new StringBuffer();<br />boolean result1 = matcher.find();<br />while (result1) {<br />matcher.appendReplacement(sb, quot; quot; );<br />result1 = matcher.find();<br />}<br />matcher.appendTail(sb);<br />return sb.toString();<br />}<br />/**<br /> * <br /> * 基本功能:过滤指定标签<br /> * <p><br /> * <br /> * @param str<br /> * @param tag<br /> * 指定标签<br /> * @return String<br /> */<br />public static String fiterHtmlTag(String str, String tag) {<br />String regxp = quot; <s*quot; + tag + quot; s+([^>]*)s*>quot; ;<br />Pattern pattern = Pattern.compile(regxp);<br />Matcher matcher = pattern.matcher(str);<br />StringBuffer sb = new StringBuffer();<br />boolean result1 = matcher.find();<br />while (result1) {<br />matcher.appendReplacement(sb, quot; quot; );<br />result1 = matcher.find();<br />}<br />matcher.appendTail(sb);<br />return sb.toString();<br />}<br />/**<br /> * <br /> * 基本功能:替换指定的标签<br /> * <p><br /> * <br /> * @param str<br /> * @param beforeTag<br /> * 要替换的标签<br /> * @param tagAttrib<br /> * 要替换的标签属性值<br /> * @param startTag<br /> * 新标签开始标记<br /> * @param endTag<br /> * 新标签结束标记<br /> * @return String<br /> * @如:替换img标签的src属性值为[img]属性值[/img]<br /> */<br />public static String replaceHtmlTag(String str, String beforeTag,<br />String tagAttrib, String startTag, String endTag) {<br />String regxpForTag = quot; <s*quot; + beforeTag + quot; s+([^>]*)s*>quot; ;<br />String regxpForTagAttrib = tagAttrib + quot; =" ([^" ]+)" quot; ;<br />Pattern patternForTag = Pattern.compile(regxpForTag);<br />Pattern patternForAttrib = Pattern.compile(regxpForTagAttrib);<br />Matcher matcherForTag = patternForTag.matcher(str);<br />StringBuffer sb = new StringBuffer();<br />boolean result = matcherForTag.find();<br />while (result) {<br />StringBuffer sbreplace = new StringBuffer();<br />Matcher matcherForAttrib = patternForAttrib.matcher(matcherForTag<br />.group(1));<br />if (matcherForAttrib.find()) {<br />matcherForAttrib.appendReplacement(sbreplace, startTag<br />+ matcherForAttrib.group(1) + endTag);<br />}<br />matcherForTag.appendReplacement(sb, sbreplace.toString());<br />result = matcherForTag.find();<br />}<br />matcherForTag.appendTail(sb);<br />return sb.toString();<br />}<br />}<br />if($this->compress){ $KindData = preg_replace(quot; ~>+~quot; , quot; >quot; , preg_replace(quot; ~>+~quot; , quot; >quot; , $KindData)); //modify 压缩 $KindData = preg_replace(quot; ~>+<~quot; , quot; ><quot; , $KindData); } <br />只压缩HTML代码,对JAVASCRIPT不影响.<br />
Descargar ahora