import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "https?://([\\w+\\-\\.]+)";
final String string = " 'https://www.amazon.com/Technology-Ventures-Enterprise-Thomas-Byers/dp/0073523429',\n"
+ " 'http://www.interactivedynamicvideo.com/',\n"
+ " 'http://www.nytimes.com/2007/11/07/movies/07stein.html?_r=0',\n"
+ " 'http://evonomics.com/advertising-cannot-maintain-internet-heres-solution/',\n"
+ " 'http://github.com/keppel/pinn',\n"
+ " 'http://phys.org/news/2015-09-scale-solar-youve.html',\n"
+ " 'https://iot.seeed.cc',\n"
+ " 'http://www.bfilipek.com/2016/04/custom-deleters-for-c-smart-pointers.html',\n"
+ " 'http://beta.crowdfireapp.com/?beta=agnipath',\n"
+ " 'https://www.valid.ly?param',\n"
+ " 'http://css-cursor.techstream.org'";
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