java - Matcher don't find on 2nd loop -
1st step everyth ok, on 2nd step goes someth wrong: slow (20+ sec) on find()
. besides matches() returs false
, , don't know why. separately every regex works fine. using emulator. thax guys.
string[] regexcontent = {"node[\\s\\s]*?(<p>[\\s\\s]+</p>)", "([\\s\\s]*?)</div>"}; pattern p; matcher m; (string regex : regexcontent){ p = pattern.compile(regex); m = p.matcher(result); //if (m.matches()) // false result = ""; if (m.find()) // on 2nd step waits long time & don't find result = m.group(m.groupcount()); m.reset(); }
if need reuse string derived matcher.group, better create new string since matcher.group still substring reference pointing original one. when second time read reference , pass pattern.matcher(), not pass exact string first step. maybe it's bug or it's designed work way. situation, create new string each time matcher.group() makes life easier. hope explained correctly , completely.
string[] regexcontent = {"node[\\s\\s]*?(<p>[\\s\\s]+</p>)", "([\\s\\s]*?)</div>"}; pattern p; matcher m; (string regex : regexcontent){ p = pattern.compile(regex); m = p.matcher(result); //if (m.matches()) // false result = ""; if (m.find()) // on 2nd step waits long time & don't find result = new string(m.group(m.groupcount())); m.reset(); }
Comments
Post a Comment