我正在尝试解析包含区域名称和组成该区域的坐标列表的文本文档。文本不是以易于解析的方式构造的,因为它是这样自由编写的:
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()
返回下一个元素而不实际修改数据结构的内部状态的东西。