LongRunningRegexExample.java public class LongRunningRegexExample { public static void main(String[] args) throws InterruptedException { final Pattern pattern = Pattern.compile("(0*)*A"); final String input = "00000000000000000000000000"; long startTime = System.currentTimeMillis(); Matcher matcher = pattern.matcher(input); matcher.find(); // runs for a long time! System.out.println("Regex took:" + (System.currentTimeMillis() - startTime) + "ms"); } } //源代码片段来自云代码http://yuncode.net