-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava4jsMatch.java
More file actions
34 lines (28 loc) · 931 Bytes
/
java4jsMatch.java
File metadata and controls
34 lines (28 loc) · 931 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
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class java4jsMatch {
public static void main(String[] args) {
String rStr = "(\\d{4})\\/(\\d{2})\\/(\\d{2})"; // 你的正则表达式
String str = "2024-11-13"; // 你要匹配的字符串
jsMatch(str,rStr);
}
public static String[] jsMatch(String input, String regex) {
List<String> strList = new ArrayList<String>();
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(input);
while (m.find()) {
for (int i = 0; i <= m.groupCount(); i++) {
strList.add(m.group(i));
}
}
String[] strArr = new String[strList.size()];
int i = 0;
for (String str : strList) {
strArr[i] = str;
i++;
}
return strArr;
}
}