stoyanmkd

e-mail-Regex

Feb 7th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. // + - space REGEX
  2.         ("[+-]+")
  3.  
  4. //Email regex 1
  5. Scanner scanner = new Scanner(System.in);
  6.         String text = scanner.nextLine();
  7.         Pattern emailPattern =
  8. Pattern.compile("([_A-Za-z0-9-]+)(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[A-Za-z]{2,})");
  9.         Matcher matcher = emailPattern.matcher(text);
  10.         while (matcher.find()) {
  11.             System.out.println(matcher.group());
  12.         }
  13. //Email regex 2
  14. String emailMatcher = "((?<=\\s)|^)([a-z0-9][a-z0-9\\-._]*[a-z0-9])@([a-z0-9][a-z0-9\\-]*[a-z0-9]\\.)+[a-z0-9]+";
  15.         Pattern pattern = Pattern.compile(emailMatcher);
  16.         Matcher matcher = pattern.matcher(text);
  17.        
  18.         while(matcher.find()) {
  19.         System.out.println(matcher.group());
  20.         }
  21. //Email regex 3
  22. String text = input.nextLine();
  23.         Pattern email = Pattern.compile("[a-zA-Z0-9]+[.-_]?[a-zA-Z0-9]+@{1}[a-zA-Z]+[.-]?[a-zA-Z]+[.]?[a-zA-Z]+");
  24.        
  25.         Matcher m = email.matcher(text);
  26.        
  27.         while (m.find()){
  28.             System.out.println(m.group());
  29.         }
Advertisement
Add Comment
Please, Sign In to add comment