-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregex.java
More file actions
55 lines (41 loc) · 1.28 KB
/
regex.java
File metadata and controls
55 lines (41 loc) · 1.28 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
package string;
public class regex {
public boolean match(char[] str, char[] pattern) {
if (str == null || pattern == null) return false;
if (str.length == 0 && str.length == pattern.length) return true;
if (String.valueOf(pattern).equals(".*")) return true;
// 贪婪匹配
int i = 0, j = 0;
boolean flag = (i < str.length && j < pattern.length);
while (flag){
while (pattern[i] == str[j] && flag) {
i++;
j++;
}
}
// while (board) {
// while (pattern[i] == str[j] && board) {
// i--;
// j--;
// }
// while (pattern[i] == '.' && board) {
// i--;
// j--;
// }
// if (pattern[i] == '*' && board) {
// while (pattern[i] != str[j] && board) {
// i--;
// }
// }
//
// if (i == 0 && j == 0) return true;
// else return false;
// }
return false;
}
public static void main(String[] args) {
regex regex = new regex();
boolean flag = regex.match("abcdefga".toCharArray(), "a.*a".toCharArray());
System.out.println(flag);
}
}