截取两个字符串中间的字符串

public String getCoupon(String couponinfo) {
String coupon = “”;
String regex = “减(.*)元”;//要获取减和元中间的字符串
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(couponinfo);// 匹配类
while (matcher.find()) {
coupon = matcher.group(1);
System.out.println(matcher.group(1));// 打印中间字符
}
return coupon;
}

你可能感兴趣的:(后端,java)