The program hangs at the moment of execution of m.find () if the line in which we are looking for has a large number of characters. It is also possible the presence of line breaks.

Has anyone encountered a similar problem? Is there any limit on the number of characters in a String. Is there any way around this?

private static String DLE = "DLE"; private static Pattern p; private static Matcher m; private static List<String> comments = new ArrayList<String>(); //Тут формируются comments.add //p = Pattern.compile(".*(?iu)(DataLife\\sEngine\\sCopyright).*"); // Было p = Pattern.compile("(?iu)DataLife\\sEngine\\sCopyright"); //Стало m = p.matcher(comments.toString()); if (m.find()) return DLE; //Пробовал также искать подобным образом - всё равно зависает :( //for (String str: comments) { // p = Pattern.compile(".*(?iu)(DataLife\\sEngine\\sCopyright).*"); // m = p.matcher(str); // if (m.find()) return DLE; //} 

UPD: The correct code is added above. It was-> It became.

    1 answer 1

    why you call ArrayList.toString (), then to optimize the expression, remove. *, they are greedy and match the entire string initially, then rollbacks start to search for DataLife\\sEngine\\sCopyright , and this can be a very long process.

    • Thanks for helping me figure it out! - korwru