获取花括号的数据包括花括号
1 public static void main(String[] args) { 2 String fileUrl = "shncchdhd${whc$%^&edmcnvf123r}fdghjhjhhj#{bfghj}dcfhdvvfjhfjhfhj#{bfghj}"; 3 Map<String, String> paramMap = new HashMap<>(); 4 String regex = "(\\$|\\#)\\{[^{}]*\\})";//匹配的是#{xxx}或者${xxx} 5 Pattern p = Pattern.compile(regex); 6 Integer count = 1; 7 Matcher matcher = p.matcher(fileUrl); 8 while (matcher.find()) { 9 String searchStr = fileUrl.substring(matcher.start(), matcher.end()); 10 if (StringUtils.isEmpty(paramMap.get(searchStr))) { 11 paramMap.put(searchStr, "${参数" + count++ + "}"); 12 } 13 } 14 System.out.println(paramMap); 15 }
获取花括号内的数据 regex = (?<={)[^}]*(?=}),若解析字符串是:aaaa{b},解析后是:b
标签:searchStr,regex,String,正则表达式,matcher,paramMap,fileUrl From: https://www.cnblogs.com/yxl-wyb/p/16856527.html