import java.net.URLEncoder; import java.util.regex.Matcher; import java.util.regex.Pattern; public class CommonInjection { //(.*)<[^>]+>(.*) //([\\s\\S]*)(?!(<[^>]+>))([\\s\\S]*) //(?!.*<[^>]+>.*).* public static final Pattern common_pattern=Pattern.compile("(?![\\s\\S]*<[\\s\\S]+>[\\s\\S]*)[\\s\\S]*"); //public static final String common_pattern_string = "[\\s\\S]*(?=ing)"; public static String fixCommonInjection(String infoStr) throws Exception{ if(infoStr == null){ return null; } Matcher matcher = common_pattern.matcher(infoStr); if(matcher.matches()){ // if(infoStr.matches(common_pattern_string)){ System.out.println("***********"); infoStr = URLEncoder.encode(infoStr, "UTF-8"); System.out.println("Matched " + infoStr); } System.out.println("Not Mathed " + infoStr); return infoStr; } public static void main(String[] args) throws Exception{ String infoStr = "script>HKJHfinfasdfing\r\nscript>\r\nTESt\r\n/script>fsafa\r\n/script><a>"; CommonInjection.fixCommonInjection(infoStr); } /*public static void main(String[] args) { String str = "HKJHfing"; String regex = "\\S(?=ing)"; String[] strs = str.split(regex); for(int i = 0; i < strs.length; i++) { System.out.printf("strs[%d] = %s%n", i, strs[i]); } } */ }