正则 转发

 

 Java 正则表达式 | 菜鸟教程

/^(((1[3|8][0-9])|(14[5|7])|(15[^4,\D])|(17[0|5|6|7|8]))\d{8})$/      手机号  
 /^[0-9]+(|-)[0-9]+(|(|-)[0-9]+)+$/       固定电话 
/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/     邮箱  
/^[0-9A-Za-z\uFF10-\uFF19\uFF41-\uFF5A\uFF21-\uFF3A\u4e00-\u9fa5\•\· ]+$/     收货人  
/^[A-Za-z0-9\uFF10-\uFF19\uFF41-\uFF5A\uFF21-\uFF3A\u4e00-\u9fa5\(\)\|\{\}\[\]\(\)\——\|\{\}\【\】\-\#\,\,\.\。]+$/      地址   
 8位长度,包含大小写字母、数字和特殊字符 "^(?=.*[A-Z])(?=.*[a-z])(?=.*\\d)(?=.*[^a-zA-Z0-9]).{8}$"

    private static final Pattern PATTERN = Pattern.compile(PASSWORD_PATTERN);
    public static boolean isValid(String password) {
        if (password == null) {
            return false;
        }
        Matcher matcher = PATTERN.matcher(password);
        return matcher.matches();
    }

  

 

@RequestMapping(value ="/{date:[0-9]{8}}/{fileName}", method = GET)
    public void redirectFileUrl(@PathVariable String date,@PathVariable String fileName, HttpServletResponse response) throws IOException {
        log.info("redirectFileUrl:"+url+"/"+bucketName+"/"+date+"/"+fileName);
        response.sendRedirect(url+"/"+bucketName+"/"+date+"/"+fileName);
    }

private static Pattern NUMBER_PATTERN = Pattern.compile("[0-9]{8}");
if(!NUMBER_PATTERN.matcher(date).matches()){//不匹配日期20230410 不拦截转发
     return;
}

 

public static final String regReasonDescAgree = "[A-Za-z0-9\uFF10-\uFF19\uFF41-\uFF5A\uFF21-\uFF3A\u4e00-\u9fa5`~!@#$%^&*()_+=\\-{}|\\[\\]:\";'<>?,.\\\\/·~!@#¥%……&*()——+\\-={}|【】、:”;’《》?,。/~]+";//

/**
* 把匹配不到的内容替换为""
* @param orgin
* @return
*/
private static String regReplace(String orgin){
try{
if(orgin == null){
return "";
}

orgin = orgin.replace("javascript", "");
orgin = orgin.replace("script", "");
orgin = orgin.replace("eval", "");

Pattern pa = Pattern.compile(regReasonDescAgree);//ð 🤪
Matcher m = pa.matcher(orgin);//"Asadf是ð短发343pðp@##@4"

StringBuffer sf = new StringBuffer();
while(m.find()){
sf.append(m.group());
sf.append(" ");
}
logger.info("policySurrenderCommit.regReplace:"+sf.toString());
return sf.toString();
} catch (Exception e){
logger.error("policySurrenderCommit.regReplace:"+orgin, e);
return orgin;
}
}

  

posted @ 2020-08-09 14:24  XUMT111  阅读(190)  评论(0)    收藏  举报