import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "http(|s):[^\\'$\\s]+";
final String string = "head: https://scooptacular.net\n"
+ "head: https://scooptacular.net/img/uploaded/379d05029c0d84618c70ac037a25fd88.jpg\n"
+ "head: https://scooptacular.net/img/uploaded/4baaa58a1a37fd3da3e4e78caf366b7f.jpg\n"
+ "head: https://fonts.googleapis.com/css?family=Montserrat:400,700\n"
+ "head: https://fonts.googleapis.com/css?family=Kaushan+Script' rel='stylesheet' type='text/css'>\n"
+ "head: https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic,700italic' rel='stylesheet' type='text/css'>\n"
+ "head: https://fonts.googleapis.com/css?family=Roboto+Slab:400,100,300,700' rel='stylesheet' type='text/css'>\n"
+ "head: https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js\n"
+ "head: https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js\n"
+ "meta: https://scooptacular.net\n"
+ "meta: https://scooptacular.net/img/uploaded/379d05029c0d84618c70ac037a25fd88.jpg\n"
+ "meta: https://scooptacular.net/img/uploaded/4baaa58a1a37fd3da3e4e78caf366b7f.jpg\n"
+ "meta: https://fonts.googleapis.com/css?family=Montserrat:400,700\n"
+ "meta: https://fonts.googleapis.com/css?family=Kaushan+Script' rel='stylesheet' type='text/css'>\n"
+ "meta: https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic,700italic' rel='stylesheet' type='text/css'>\n"
+ "meta: https://fonts.googleapis.com/css?family=Roboto+Slab:400,100,300,700' rel='stylesheet' type='text/css'>\n"
+ "meta: https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js\n"
+ "meta: https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js\n"
+ "meta: https://scooptacular.net\n"
+ "meta: https://scooptacular.net/img/uploaded/379d05029c0d84618c70\n"
+ "http://google.com.ar\n\n";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html