import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(https?:\\/\\/)?(w{3}\\.)?(\\w+\\.\\w{2,3}\\.\\w{2}?)?(\\w+-)?(:?%?\\w{2,}\\/?\\.\\w{2,3})?(\\/\\w+)?(\\/[\\d\\w].+\\s$)?(:\\d+)?";
final String string = "\n\n"
+ "https://www.google.co.in/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=trie+data+structure+tutorial+%7C+explanation\n"
+ "http://vnc.example.com:5800 \n"
+ "gskinner.com/products/spl\n"
+ "gskinner.com\n"
+ "adobe.com/go/flex\n"
+ "google.in\n"
+ "http://boswebsvr009:8090/confluence/display/DEV/Training+for+2015+batch+junior+engineers";
final Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
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