input data:
File Name=TEST.txt
File Content=test1
test2
test3
Pattern pattern = Pattern.compile("File Name=(.*)", Pattern.MULTILINE);
Matcher matcher = pattern.matcher(data);
if (matcher.find()) {
System.out.println(matcher.group(1));
}
pattern = Pattern.compile("File Comtent=(.*)", Pattern.DOTALL);
matcher = pattern.matcher(data);
if (matcher.find()) {
System.out.println(matcher.group(1));
}
输出:
TEST.txt
test1
test2
test3