import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "([\\:][\\/]{0,2})[\\w\\-]+([\\@]|[\\.])?([\\w\\-]+[\\.]){0,}([\\w\\-]+)?([\\:][\\d]+)?[\\/]?";
final String string = "https://user_test-teste@regex101.com:80/\n"
+ "http://localhost:80/\n"
+ "https://tools.ietf.org/html/rfc3986#page-7\n"
+ "https://translate.google.com.br/#en/pt/that%20what\n"
+ "https://www.google.com.br/search?client=firefox-b&biw=1920&bih=1001&q=overload+inexistent+property+php&oq=overload+inexistent+property+php&gs_l=psy-ab.3..33i22i29i30k1.36919.57166.0.57324.38.36.2.0.0.0.682.3958.14j18j5-1.33.0....0...1.1.64.psy-ab..3.27.3324...0j35i39k1j0i131k1j0i67k1j0i10k1j0i22i30k1j33i160k1j33i21k1.m5dBRh4nQ-I";
final Pattern pattern = Pattern.compile(regex);
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