Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // + - space REGEX
- ("[+-]+")
- //Email regex 1
- Scanner scanner = new Scanner(System.in);
- String text = scanner.nextLine();
- Pattern emailPattern =
- Pattern.compile("([_A-Za-z0-9-]+)(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[A-Za-z]{2,})");
- Matcher matcher = emailPattern.matcher(text);
- while (matcher.find()) {
- System.out.println(matcher.group());
- }
- //Email regex 2
- String emailMatcher = "((?<=\\s)|^)([a-z0-9][a-z0-9\\-._]*[a-z0-9])@([a-z0-9][a-z0-9\\-]*[a-z0-9]\\.)+[a-z0-9]+";
- Pattern pattern = Pattern.compile(emailMatcher);
- Matcher matcher = pattern.matcher(text);
- while(matcher.find()) {
- System.out.println(matcher.group());
- }
- //Email regex 3
- String text = input.nextLine();
- Pattern email = Pattern.compile("[a-zA-Z0-9]+[.-_]?[a-zA-Z0-9]+@{1}[a-zA-Z]+[.-]?[a-zA-Z]+[.]?[a-zA-Z]+");
- Matcher m = email.matcher(text);
- while (m.find()){
- System.out.println(m.group());
- }
Advertisement
Add Comment
Please, Sign In to add comment