forked from JustinSDK/JavaSE6Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUseRegularExpression.java
More file actions
43 lines (34 loc) · 1.31 KB
/
UseRegularExpression.java
File metadata and controls
43 lines (34 loc) · 1.31 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
import java.io.*;
public class UseRegularExpression {
public static void main(String args[])
throws IOException {
BufferedReader reader =
new BufferedReader(
new InputStreamReader(System.in));
System.out.println("abcdefgabcabc".replaceAll(".bc", "###"));
String phoneEL = "[0-9]{4}-[0-9]{6}";
String urlEL = "<a.+href*=*['\"]?.*?['\"]?.*?>";
String emailEL = "^[_a-z0-9-]+(.[_a-z0-9-]+)*" +
"@[a-z0-9-]+(.[a-z0-9-]+)*$";
System.out.print("輸入手機號碼: ");
String input = reader.readLine();
if(input.matches(phoneEL))
System.out.println("格式正確");
else
System.out.println("格式錯誤");
System.out.print("輸入href標籤: ");
input = reader.readLine();
// 驗證href標籤
if(input.matches(urlEL))
System.out.println("格式正確");
else
System.out.println("格式錯誤");
System.out.print("輸入電子郵件: ");
input = reader.readLine();
// 驗證電子郵件格式
if(input.matches(emailEL))
System.out.println("格式正確");
else
System.out.println("格式錯誤");
}
}