正则表达式中的贪婪和非贪婪匹配
import java.util.regex.Matcher; import java.util.regex.Pattern; /* nowjava */ public class Main { public static void main(String[] args) { // Greedy quantifiers String match = find("A.*c", "AbcAbc"); // AbcAbc match = find("A.+", "AbcAbc"); // AbcAbc // Nongreedy quantifiers match = find("A.*?c", "AbcAbc"); // Abc match = find("A.+?", "AbcAbc"); // Abc }/** 时 代 J a v a 公 众 号 - nowjava.com 提供 **/ public static String find(String patternStr, CharSequence input) { Pattern pattern = Pattern.compile(patternStr)