SHARE
TWEET

ExtractEmails

a guest Mar 24th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2. import java.util.regex.Matcher;
  3. import java.util.regex.Pattern;
  4.  
  5. public class ExtractEmail {
  6.     public static void main(String[] args) {
  7.         Scanner scanner=new Scanner(System.in);
  8.  
  9.  
  10.  
  11.         String regex="\\s[A-Za-z][\\w.-]*@[A-Za-z-]+(\\.[A-Za-z]+)+";
  12.         String input=scanner.nextLine();
  13.         Pattern pattern=Pattern.compile(regex);
  14.  
  15.         Matcher matcher=pattern.matcher(input);
  16.  
  17.         while (matcher.find()){
  18.             System.out.println(matcher.group(0).trim());
  19.         }
  20.     }
  21. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top