-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem3.java
More file actions
17 lines (15 loc) · 817 Bytes
/
Copy pathProblem3.java
File metadata and controls
17 lines (15 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// Source: https://web.archive.org/web/20240117011501/https://regexone.com/problem/matching_emails
import java.util.regex.Pattern;
public class Problem3 {
public static void main(String[] args) {
// Does not handle any special characters in the email or subdomain emails!
String regex = "^([\\w\\.]+)\\+?[\\w\\.]*@([\\w\\.]+)$";
assert Pattern.matches(regex, "tom@hogwarts.com");
assert Pattern.matches(regex, "tom.riddle@hogwarts.com");
assert Pattern.matches(regex, "tom.riddle+regexone@hogwarts.com");
assert Pattern.matches(regex, "tom@hogwarts.eu.com");
assert Pattern.matches(regex, "potter@hogwarts.com");
assert Pattern.matches(regex, "harry@hogwarts.com");
assert Pattern.matches(regex, "hermione+regexone@hogwarts.com");
}
}