-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregex_basic.java
More file actions
27 lines (25 loc) · 1001 Bytes
/
regex_basic.java
File metadata and controls
27 lines (25 loc) · 1001 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
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class regex {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Welcome, Please enter your email ID for the registration");
String str = sc.nextLine();
Pattern p = Pattern.compile("[a-zA-Z0-9_.]+[@](gmail|yahoo|rediff)[.]com");
Matcher m = p.matcher(str);
int ctr = 0;
/*here if the match is found then the index start from and ending points are printed and the group of that find pattern also printed*/
while(m.find()){
System.out.println(m.start()+ "--"+ m.end()+ "--"+m.group());
ctr++;
}
if(ctr==0){
System.out.println("Invalid Input, Please enter the valid format");
}
else {
System.out.println("Congratulations,You are registered successfully!");
System.out.println(ctr);
}
}
}