-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaRegex.java
More file actions
36 lines (24 loc) · 887 Bytes
/
JavaRegex.java
File metadata and controls
36 lines (24 loc) · 887 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
//Validating an email address of domain: samarthbais using regular expression in Java
/*
* ^ - starting of the matching regex
* $ - ending of the matching regex
* \\w - Any alphanumeric character
* \\. - Dot character
* + - More than one character
*/
public class JavaRegex {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String email = sc.next();
Pattern p = Pattern.compile("^\\w+@samarthbais\\.com$");
Matcher matcher = p.matcher(email);
if(matcher.find()){
System.out.println("The Person has a valid samarthbais account!");
}
else
System.out.println("This is not a valid samarthbais account!");
}
}