[JAVA/JSP] 정규표현식 스크립트 제거 Regex Replace Function
<script~, onclick=~, onmouseover=~, onmouseout=~ 제거함수
정규표현식 클래스 임포트
함수
정규표현식 클래스 임포트
import java.util.regex.*;
함수
public String getRemoveScript(String strContent){
Pattern patternTag=Pattern.compile("\\<(\\/?)(\\w+)*([^<>]*)>");
Pattern patternScript=Pattern.compile("(?i)\\<script(.*?)</script>");
Pattern patternMouseOver=Pattern.compile("(?i) onmouseover=[\"']?([^>\"']+)[\"']*");
Pattern patternMouseOut=Pattern.compile("(?i) onmouseout=[\"']?([^>\"']+)[\"']*");
Pattern patternMouseClick=Pattern.compile("(?i) onclick=[\"']?([^>\"']+)[\"']*");
Matcher matcherContent=patternScript.matcher(strContent);
strContent=matcherContent.replaceAll("");
Matcher matcherMouseOver=patternMouseOver.matcher(strContent);
strContent=matcherMouseOver.replaceAll("");
Matcher matcherMouseOut=patternMouseOut.matcher(strContent);
strContent=matcherMouseOut.replaceAll("");
Matcher matcherMouseClick=patternMouseClick.matcher(strContent);
strContent=matcherMouseClick.replaceAll("");
return strContent;
}
Pattern patternTag=Pattern.compile("\\<(\\/?)(\\w+)*([^<>]*)>");
Pattern patternScript=Pattern.compile("(?i)\\<script(.*?)</script>");
Pattern patternMouseOver=Pattern.compile("(?i) onmouseover=[\"']?([^>\"']+)[\"']*");
Pattern patternMouseOut=Pattern.compile("(?i) onmouseout=[\"']?([^>\"']+)[\"']*");
Pattern patternMouseClick=Pattern.compile("(?i) onclick=[\"']?([^>\"']+)[\"']*");
Matcher matcherContent=patternScript.matcher(strContent);
strContent=matcherContent.replaceAll("");
Matcher matcherMouseOver=patternMouseOver.matcher(strContent);
strContent=matcherMouseOver.replaceAll("");
Matcher matcherMouseOut=patternMouseOut.matcher(strContent);
strContent=matcherMouseOut.replaceAll("");
Matcher matcherMouseClick=patternMouseClick.matcher(strContent);
strContent=matcherMouseClick.replaceAll("");
return strContent;
}