public static void main(String[] args) { String str = "http://www.baidu.com/aa http://www.baidu.com/sss"; Matcher matcher = Pattern.compile("(http://www.baidu.com[^\\s]+)").matcher(str); while(matcher.find()){ System.out.println(matcher.group()); } }