Java Regex
Java.util.Regex
Pattern Matcher
正则表达式开始符号: `^`
结束符号:`$`
java转义: \\
Matcher中的group: (regexStr)
group name: (?<name>regexStr)
String patternStr = "^(?<date>\\d{8})\\.(?<cluster>\\w*)\\.(?<index>\\w*)\\.(?<operation>create|update)\\.(?<ohter>.*)$";
Pattern pattern = Pattern.compile(patternStr);
String testStr1 = "20190317.cluster.index.create.yml";
String testStr2 = "20190318.cluster.index.update.yml";
String testStr3 = "20190319.cluster.index.delete.yml";
List<String> testList = Arrays.asList(testStr1, testStr2, testStr3);
testList.stream()
.map(test -> pattern.matcher(test))
.forEach(matcher -> {
if (matcher.matches()) {
System.out.println(matcher.group("date"));
System.out.println(matcher.group("cluster"));
System.out.println(matcher.group("operation"));
}
});
https://docs.oracle.com/javase/8/docs/api/java/util/regex/Matcher.html
网络上志同道合,我们一起学习网络安全,一起进步,QQ群:694839022