No matches found on loop 2

1st step - everything is fine, but something goes wrong at the 2nd step: it is very slow (20 + sec) on find() . Also, match () always returns false , and I don't know why. Separately, each regular expression works fine. Using an emulator. Thax.

  String[] regexContent = {"node[\\s\\S]*?(<p>[\\s\\S]+</p>)", "([\\s\\S]*?)</div>"}; Pattern p; Matcher m; for (String regex : regexContent){ p = Pattern.compile(regex); m = p.matcher(result); //if (m.matches()) // always false result = ""; if (m.find()) // on 2nd step waits for so long time & don't find result = m.group(m.groupCount()); m.reset(); } 
0
java android regex
Sep 04 '13 at 0:50
source share
1 answer

If you really need to reuse the String obtained from Matcher.group, it is better to create a new line, since what you get from Matcher.group is actually a substring whose link points to the original one. Thus, when you read the link a second time and go to Pattern.matcher (), you are not actually passing the exact string that you get from the first step. Perhaps this is a mistake or it is designed to work in this way. But for your situation, create a new line every time Matcher.group () always makes life easier. I hope I have explained this correctly and completely.

 String[] regexContent = {"node[\\s\\S]*?(<p>[\\s\\S]+</p>)", "([\\s\\S]*?)</div>"}; Pattern p; Matcher m; for (String regex : regexContent){ p = Pattern.compile(regex); m = p.matcher(result); //if (m.matches()) // always false result = ""; if (m.find()) // on 2nd step waits for so long time & don't find result = new String(m.group(m.groupCount())); m.reset(); } 
0
Sep 04 '13 at 4:55 on
source share



All Articles