zoukankan      html  css  js  c++  java
  • 相互匹配两个list集合+动态匹配${}参数

    /**
    * @describe java中字符串参数化符号${}的正则解析
    * @author cxy
    * @date 2019年10月10日16:23:41
    *
    */

    public class RegExp {

    public boolean match(String reg, String str) {
    return Pattern.matches(reg, str);
    }

    public List<String> find(String reg, String str) {
    Matcher matcher = Pattern.compile(reg).matcher(str);
    List<String> list = new ArrayList<String>();
    while (matcher.find()) {
    list.add(matcher.group());
    }
    return list;
    }

    public List<String> find(String reg, String str, int index) {
    Matcher matcher = Pattern.compile(reg).matcher(str);
    List<String> list = new ArrayList<String>();
    while (matcher.find()) {
    list.add(matcher.group(index));
    }
    return list;
    }

    public String findString(String reg, String str, int index) {
    String returnStr = null;
    List<String> list = this.find(reg, str, index);
    if (list.size() != 0){
    returnStr = list.get(0);
    }
    return returnStr;
    }

    public String findString(String reg, String str) {
    String returnStr = null;
    List<String> list = this.find(reg, str);
    if (list.size() != 0){
    returnStr = list.get(0);
    }
    return returnStr;
    }

    public List<String> getKeywords(String p){
    String reg = "(?<=(?<!\\)\$\{)(.*?)(?=(?<!\\)\})";
    RegExp re = new RegExp();
    List<String> list = re.find(reg, p);
    return list;
    }
    }

    String smsContent = "这是${phone}我的${busi_type}一批${business_hall}测试数据${duration}2019年10月11日14:47:06";

    RegExp re = new RegExp();
    List<String> list = re.getKeywords(smsContent);

    //后台查询

    List<Object> spList = this.baseSmsService.selectParamsByTypeAndCode(vo);
    Map<String,String> map = new HashMap<String,String>();
    ArrayList<String> arr = new ArrayList<String>();
    for(int i=0;i<spList.size();i++){//遍历查询到的结果集,并将paramKey封装进一个ArrayList中
    map = (Map<String,String>)spList.get(i);
    arr.add(map.get("PARAMKEY"));
    }

    //匹配用户输入的动态参数是否存在——遍历一个一个判断
    for(int i=0;i<list.size();i++){
      System.out.println(list.get(i) + "是否已经存在" + arr.contains(list.get(i)));
    }

    //匹配用户输入的动态参数是否存在——全量匹配,只有list中的全部元素都存在于arr中,才返回true

    System.out.println(arr .containsAll(list));

  • 相关阅读:
    谢尔排序(缩小增量排序)
    折半插入排序
    插入排序
    选择排序
    冒泡排序
    ul+js模拟select+改进
    ul+js模拟select
    前端面试题
    js数组去重的三种常用方法总结
    使用PHP实现文件上传和多文件上传
  • 原文地址:https://www.cnblogs.com/ying1314/p/11654183.html
Copyright © 2011-2022 走看看