FileReader reader = new FileReader("f://file.TextGrid");
BufferedReader br = new BufferedReader(reader);
Pattern sizePattern = Pattern.compile("(^size)+(.)+[0-9]+");
Pattern xmPattern = Pattern.compile("(xm)(.)+(\\d+\\.)?\\d+");
String strText;
int lineIndex = 0;
while ((strText = br.readLine()) != null) {
Matcher sizeMatcher = sizePattern.matcher(strText);
Matcher xmMatcher = xmPattern.matcher(strText);
while(xmMatcher.find()){
if(xmMatcher.group() != null) {
for(int j = 0; j < xmMatcher.groupCount(); j++)
System.out.println(xmMatcher.group(j));
}
}
}
br.close();
reader.close();
输出结果是:
xmin = 0.000000
xm
0
只想要第一行,请问错误在那?估计是groupCount的问题,请指教,谢谢
------解决方案--------------------
- Java code
只要第一行System.out.println(xmMatcher.group(0));给j变成0了一般group(0)代表整体匹配到的!