我正在使用while(matcher.find())
循环并从文件中检索内容。我想知道如果我知道我找到的索引位于matcher.start()
.
我很困惑,有人可以解释一下吗?
String expr = "<[^<?!>]+>";
String[] response = new String[5];
Pattern p = Pattern.compile(expr);
Matcher m = p.matcher(xmlDocument);
while (m.find()) {
// System.out.println(m.group() + " located at " + m.start());
// txtMatches.append(m.group() + " located at " + m.start() + "\n");
if (itemStack.getCount() == 0 && m.group().contains("</")) {
response[0] = "Orphan closing tag" ;
response[1] = stripUnwantedChars(m.group(), true);
response[2] = String.valueOf(m.start()); //right here is where i want to return line number
return response;
}
//rest of code
itemStack
是一堆推送的匹配项,然后我将它们进行比较以查看堆栈中是否没有更多项目,但有一个带有结束标记的匹配项。