Two matched list set {+} $ dynamic matching parameters

/ **
* @describe Java string parametric symbol $ {} regular analytic
* @author Cxy
* 2019 years @date dated 10 Day 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 = "This is $ {phone} my $ {busi_type} $ {business_hall} batch of test data $ {duration} 2019 Nian 10 Yue 11 Ri 14:47:06";

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

// background check

List <Object> = SPList this.baseSmsService.selectParamsByTypeAndCode (VO);
the Map <String, String> = new new the HashMap Map <String, String> ();
the ArrayList <String> new new ARR = the ArrayList <String> ();
for (int i = 0; i <spList.size ( ); i ++) {// query to traverse the result set, and ArrayList paramKey encapsulated in a
Map = (the Map <String, String>) spList.get (I);
ARR .add (as map.get ( "PARAMKEY"));
}

// user input matches the dynamic parameters are present - a traversing a determination
for (int I = 0; I <list.size (); I ++) {
  System.out.println (List.get (I) + "whether presence "+ arr.contains (List.get (I)));
}

 

// matches the user input dynamic parameters are present - full matching amount, only the list of all the elements are present in arr, the only return true

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

Guess you like

Origin www.cnblogs.com/ying1314/p/11654183.html