您的位置 首页 java

Java正则最短匹配

Java正则最短匹配

懒惰限定符:

*? 重复任意次,但尽可能少重复(最短匹配,非贪婪匹配)

+? 重复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 ());
        }
    }
}
  

文章来源:智云一二三科技

文章标题:Java正则最短匹配

文章地址:https://www.zhihuclub.com/182714.shtml

关于作者: 智云科技

热门文章

网站地图