desislava_topuzakova

06. Extract Emails

Mar 17th, 2023
678
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. package RegEx;
  2.  
  3. import java.util.Scanner;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. public class ExtractEmails_06 {
  8. public static void main(String[] args) {
  9. Scanner scanner = new Scanner(System.in);
  10.  
  11. String regex = "[0-9A-Za-z]+[.\\-_]?[0-9A-Za-z]+@[A-Za-z]+-?[A-Za-z]+(\\.[A-Za-z]+-?[A-Za-z]+)+";
  12. Pattern pattern = Pattern.compile(regex);
  13.  
  14. String text = scanner.nextLine();
  15. Matcher matcher = pattern.matcher(text);
  16. //text = "Just send email to [email protected] and [email protected] for more information."
  17.  
  18. while (matcher.find()) {
  19. System.out.println(matcher.group());
  20. }
  21. }
  22. }
  23.  
Advertisement
Add Comment
Please, Sign In to add comment