import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^http(s)?:\\/\\/([^\\/]+)";
final String string = "https://kdl.ru/patient/blog/omega-3-piti-ili-ne-piti\n"
+ "https://apteka-april.ru/blog/intresting-and-useful/37-chto-takoe-omega-3\n"
+ "https://galina-erikson.ru/poleznye-dlya-zdorovya-stati/a-vy-znaete-kak-pravilno-vybrat-preparat-omega-3\n"
+ "https://omega-labs.ru/\n"
+ "https://www.sportfood40.ru/articles/kak-vybrat-omega-3/\n"
+ "https://www.kp.ru/expert/elektronika/luchshie-noutbuki-dlya-raboty/\n"
+ "https://yandex.ru/video/preview/11052470352245519618?text=какой ноутбук купить для работы&path=yandex_search&parent-reqid=1678203470996582-5656932453459637239-sas3-0967-c7e-sas-l7-balancer-8080-BAL-6300&from_type=vast\n"
+ "https://www.OZON.ru/club/article/roboty-pylesosy-reyiting-modeleyi-dlya-chistoty-v-kvartire-16303710/\n"
+ "https://рейтинг-лучшего.рф/rejtingi/luchshie-detskie-smart-chasy/\n"
+ "https://mobilegadjet.ru/sravneniya/2340-";
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