- /**
- * String p="(2;10+3;50)|((1;20+3;3001)|7;2001)";
- String m = "2;1001+3;5012+7;200102"; 测返回(true&&true)||((false&&false)||true) 2;1001 是2;10的子类
- *
- * @param exp 表达式
- * @param catelogs 分类
- * @return
- */
- public static String regexExpression(String exp ,String catelogs){
- Pattern pattern = Pattern.compile("[0-9]{1,5}\\\\;[0-9]{1,20}");
- Matcher matcher = pattern.matcher(exp);
- String[] seg = exp.split("[0-9]{1,5}\\\\;[0-9]{1,20}");
- List<String> list = new ArrayList<String>();
- while(matcher.find()){
- list.add(matcher.group(0)) ;
- }
- for(int i =0;i<list.size();i++){
- String it = list.get(i);
- if(catelogs.indexOf(it)!=-1){
- list.set(i, "true");
- }else{
- list.set(i, "false");
- }
- }
- String tmp ="";
- for(int i =0;i<list.size();i++){
- tmp+=(seg[i]+list.get(i));
- }
- tmp+=seg[list.size()];
- return tmp.replaceAll("\\\\|", "||").replaceAll("\\\\+","&&");
- }
- //该片段来自于http://www.codesnippet.cn/detail/0810201410550.html
来源: http://www.codesnippet.cn/detail/0810201410550.html