java.lang.IllegalStateException: No match found错误

public class Zhengze {
	public static void main(String args[]){
		Pattern p = Pattern.compile("经度(.*)纬度(.*)");
		Matcher m = p.matcher("经度1121212纬度4343543");
		while(m.find()){
			System.out.println(m.group(1)+"\n"+m.group(2));
		}
		
		Pattern s = Pattern.compile("经度(.*)纬度(.*)");
		Matcher k = s.matcher("经度1121212纬度4343543");
		System.out.println(k.group(1));
		
	}


}

第二个报错,格式不对,需要有判断 m.find()


Pattern s = Pattern.compile("逻辑地址:(.*)");
Matcher k = s.matcher("逻辑地址:北京");
while(k.find()){
	System.out.println(k.group(1));
}

错误,中英文冒号不同,匹配不到


Pattern p = Pattern.compile("逻辑地址:(.*)");
Matcher m = p.matcher("逻辑地址:");
while(m.find()){
	String regex = m.group(1);
	if(regex == null)
		regex = "没有地址";
}


错误,java应该用regex.equals("")

你可能感兴趣的:(android)