---
title: "×与×？的区别--正则匹配取匹配量词的最小值最大值"
author: "iammonster"
date: "2009-07-07T15:55:45Z"
tags: []
slug: "untitled"
draft: false
lastmod: "2009-07-07T15:56:51Z"
id: 421312
url: "https://jiajun.iteye.com/blog/421312"
---

**关于Greedy、Reluctant与Possessive:**

Greedy: 在能匹配的前提下，取量词的最大值。  
Reluctant: 在匹配的前提下，取量词的最小值。  
Possessive: 取量词的最大值，无论匹配与否。  
如：  
Pattern.compile("^.\*B").matcher("AABAABAA") : "AABAAB"  
Pattern.compile("^.\*?B").matcher("AABAABAA") : "AAB"  
Pattern.compile("^.\*+B").matcher("AABAABAA") : null

目前为止我还没有体会到Possessive的用处。