desislava_topuzakova

06. Extract Emails

Jul 31st, 2021
1,374
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.*;
  2. import java.util.regex.Matcher;
  3. import java.util.regex.Pattern;
  4. import java.util.stream.Collectors;
  5.  
  6. public class demo {
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.         String regexEmail = "[A-Za-z0-9]+[._-]?[A-Za-z0-9]+@[A-Za-z]+-?[A-Za-z]+(\\.[A-Za-z]+-?[A-Za-z])+";
  10.         Pattern pattern = Pattern.compile(regexEmail);
  11.         String input = scanner.nextLine();
  12.  
  13.         Matcher matcher = pattern.matcher(input);
  14.  
  15.         while(matcher.find()) {
  16.             System.out.println(matcher.group());
  17.         }
  18.  
  19.  
  20.  
  21.  
  22.  
  23.     }
  24. }
RAW Paste Data