Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- Pattern pattern = Pattern.compile("(http://|https://)?(www.)?([\\w.]+\\.\\w+)");
- List<String> lines = asList("Говно залупа",
- "Ссылка на http://www.pikabu.ru",
- "Две ссылки https://vk.com/im?peers=20362018&sel=70935046 и конечно-же pornhub.nebo.allah.ru, вот!");
- lines.forEach(line -> {
- Matcher matcher = pattern.matcher(line);
- List<String> allMatches = new ArrayList<>();
- while (matcher.find()) {
- allMatches.add(matcher.group().);
- }
- if (allMatches.isEmpty()) {
- System.out.println(String.format("Нихуя не найдено в строке '%s'", line));
- } else {
- System.out.println(String.format("В строке '%s' нашлись: %s", line, allMatches));
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement