懒惰限定符:
*? 重复任意次,但尽可能少重复(最短匹配,非贪婪匹配)
+? 重复1次或更多次,但尽可能少重复
?? 重复0次或1次,但尽可能少重复
{n,m}? 重复n到m次,但尽可能少重复
{n,}? 重复n次以上,但尽可能少重复
public class Main {
public static void main(String[] args) {
String demo = "#{name}8#{demo}";
Pattern pattern = Pattern.compile("#{(.*?)}");
Matcher matcher = pattern.matcher(demo);
while (matcher.find()) {
System.out.println(matcher. group ());
}
}
}