import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class helloWorld2 {
private static final String TRACK_SEPARATE = ",";
public static void main(String[] args) {
String str = "\t<html>\n" +
"\t\t<body>\n" +
"\t\t\t<a href=\"http://stackoverflow.com/questions/ask-1-1-1\" / >\n" +
"\t\t\t<a href=\"http://stackoverflow.com/questions/ask\" >kkkkkk</a>\n" +
"\t\t\t<img width=\"584\" height=\"154\" alt=\"BIGLOBE WiMAX 2+\" src=\"http://img.google.com/images/shopbnr/imax2_160517_584_154\">\n" +
"\t\t</body>\n" +
"\t</html>";
getStrings(str);
}
private static void getStrings( String str) {
Pattern p = Pattern.compile("((http[s]{0,1}|ftp)://[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)|((www.)|[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)");
Matcher m = p.matcher(str);
ArrayList<String> strs = new ArrayList<String>();
while (m.find()) {
strs.add(m.group(1));
}
for (String s : strs){
System.out.println(s);
}
}
}
http://stackoverflow.com/questions/ask-1-1-1
http://stackoverflow.com/questions/ask
http://img.gpoint.co.jp/images/shopbnr/biglobewimax2_160517_584_154
Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8
Process finished with exit code 0
Pattern p = Pattern.compile("((http[s]{0,1}|ftp)://[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)|((www.)|[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)");