我正在尝试从html页面获取地址。我有一个正则表达式,我从中发现州,城市和电话号码。
String linearray[] = newdoc.split("\n");
int count = 0;
System.out.println(linearray.length);
while(count<linearray.length)
{
System.out.println(count);
Pattern pattern = Pattern.compile("(.*?)(\\d{1,4}(\\s*\\w*)*)(\\s*)(CA|AZ|NY)(\\s*)(\\(?[1-9]\\d{2}\\)?\\s*\\d{3}\\d{4})?(.*?)");
Matcher matcher = pattern.matcher(linearray[count].trim());
while (matcher.find()) {
String state = matcher.group(5);
String city = matcher.group(2);
String phone = matcher.group(7);
System.out.println("state "+state+" city "+city+" phone "+phone+" ");
}
count++;
}
当我尝试运行此代码时,它会进入无限循环。 任何人都可以帮我解决这个问题吗?
编辑:
linearray[count]=="Bombay Garden Newark SanMateo SantaClara © 2011 Bombay Garden All Rights Reserved"
时,我的代码卡在while(matcher.find())
行上。知道为什么会卡在那里吗?当我跳过那一行(通过使用继续)时,代码终止就好了!