【发布时间】:2011-10-12 11:27:38
【问题描述】:
我正在尝试解析包含区域名称和组成该区域的坐标列表的文本文档。文本的结构不是很容易解析,因为它是这样写的:
GUZ06—卡布尔彻河
以从 开始的线为界的区域 大陆上的海洋公园边界与 与南纬 27°08.981' 平行(在或大约在 27°08.981' 南,153°01.822' 东)然后逐渐运行—— (a) 通常向西北和东南方向(通过卡布尔彻 河)沿大陆海洋公园边界到其 与东经153°02.197'子午线相交(在或 大约南纬 27°08.762',东经 153°02.197');和
...
GUZ07-[...]
我想做的是匹配一个区域的名称,然后找到下一个区域在哪里,提取两个匹配点之间的文本块,然后运行我的坐标提取逻辑该文本块,使用类似:
while (matcher.find()) {
int textStart = matcher.end() + 1; //remember the end of the current title
matcher.find(); //find the start of the next title
String regionData = myBigString.substring(textStart, matcher.start()); //extract the text for this region
//[process the region data]
matcher.forgetLastFind(); //need to go back so that the next iteration starts from the correct place
}
当然,forgetLastFind() 不是真实的东西。有没有办法使用Matcher API 来近似这种行为?理想情况下,我想要像 Stack.peek() 这样的东西,它返回下一个元素而不实际修改数据结构的内部状态。
【问题讨论】: