You could either try to find the index of the protocol substring ("http[s]") in the Strings, or use a simple Pattern
(only for matching the "website[0-9]" head, not to apply to the URLs).
Here's a solution with the Pattern
.
String webSite1 = "WEBSITE1 https://localhost:8080/admin/index.php?page=home";
String webSite2 = "WEBSITE2 https://192.168.0.3:8084/index.php";
String webSite3 = "WEBSITE3 https://192.168.0.5:9090/controller/index.php?page=home";
String webSite4 = "WEBSITE4 https://192.168.0.1:8080/home/index.php?page=forum";
ArrayList<URI> uris = new ArrayList<URI>();
Pattern pattern = Pattern.compile("^website\\d+\\s+?(.+)", Pattern.CASE_INSENSITIVE);
Matcher matcher;
matcher = pattern.matcher(webSite1);
if (matcher.find()) {
try {
uris.add(new URI(matcher.group(1)));
}
catch (URISyntaxException use) {
use.printStackTrace();
}
}
matcher = pattern.matcher(webSite2);
if (matcher.find()) {
try {
uris.add(new URI(matcher.group(1)));
}
catch (URISyntaxException use) {
use.printStackTrace();
}
}
matcher = pattern.matcher(webSite3);
if (matcher.find()) {
try {
uris.add(new URI(matcher.group(1)));
}
catch (URISyntaxException use) {
use.printStackTrace();
}
}
matcher = pattern.matcher(webSite4);
if (matcher.find()) {
try {
uris.add(new URI(matcher.group(1)));
}
catch (URISyntaxException use) {
use.printStackTrace();
}
}
System.out.println(uris);
Output:
[https://localhost:8080/admin/index.php?page=home, https://192.168.0.3:8084/index.php, https://192.168.0.5:9090/controller/index.php?page=home, https://192.168.0.1:8080/home/index.php?page=forum]