截取某两个字符之间的数据
// String filetext = "=G10-[0,-1@]!G10|>0?(=G10-[0,-1@]!G10|>0?0:-1):(D15=0?0:-1)";
// Pattern p = Pattern.compile("\\=(.*?)\\|");//正则表达式,取=和|之间的字符串,不包括=和|// Matcher m = p.matcher(filetext);
// while(m.find()) {
// System.out.println(m.group(1));//m.group(1)不包括这两个字符
//
// }
对于截取的字符串进行替换
String regex = "\\{(.+?)\\}";
String str = "{G10-[0,-1@]!G10}>0?({G10-[0,-1@]!G10}>0?0:-1):(D15=0?0:-1)" ;
List<Match> list=new ArrayList<Match>();
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(str);
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
System.out.println(matcher.group(1));
System.out.println(">>>>> replace sequence : " + matcher.group(0));
System.out.println(">>>>> index range : (" + matcher.start() + ", " + matcher.end() + ")");
System.out.println(">>>>> sub : " + str.substring(matcher.start(), matcher.end()));
matcher.appendReplacement(sb, "123");
System.out.println("-----------------");
}
matcher.appendTail(sb);
System.out.println(">>>> sb : " + sb.toString());