-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegularExpression.java
More file actions
73 lines (54 loc) · 1.74 KB
/
RegularExpression.java
File metadata and controls
73 lines (54 loc) · 1.74 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package chap5;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
// Check correct or seach
public class RegularExpression {
private static int i=0;
public static void main(String[] args) {
/* String[] fullName={"Trieu Van Than","Nguyen Thi Hoa","To Trong Phu","Ngo Van Tai","Le Duc Anh",
"Do Viet Hung","Tran Thuy Ha"};
String regex=".*Th.*";
Pattern pattern =Pattern.compile(regex);
Matcher matcher;
for (int i=0;i<fullName.length;i++)
{
matcher=pattern.matcher(fullName[i]);
if(matcher.find())
{
System.out.println(fullName[i]);
}
}*/
/*
// Replace String with Regular Expresstion
String input=" Hello Phan Hong Son ";
String regex="[\\s]+";
Pattern pattern=Pattern.compile(regex);
Matcher matcher=pattern.matcher(input);
if(matcher.find())
{
System.out.println(matcher.replaceAll("_"));
}
*/
//Check Type Email use RegularExpresstion
Scanner input= new Scanner(System.in);
while (i!=1)
{
System.out.println("Please insert your mail");
String inp =input.nextLine();
//String input ="sonbkproksnb90@@gmail.com";
String regex="^\\w+[a-z0-9]*@{1}\\w+mail.com$";
Pattern pattern=Pattern.compile(regex);
Matcher matcher =pattern.matcher(inp);
if(matcher.find())
{
i=1;
System.out.println("You correct");
}
else
{
System.out.println("In correct. Please return");
}
}
}
}