java - 在Java正则表达式中剪切多行文本的一部分
问题描述
我有以下文字:
(Some text before...)
display_name = lo
name = lo
is_up = 1
index = 1
is_virtual = 0
is_point_to_point = 0
MTU = 65536
hardware_address = (null)
parent = (null)
ip_counter = 2
inet6 addr = /::1
inet addr = /127.0.0.1
---------------End_of_text---------------------
(Some text after...)
我试图在“display_name = lo”和“---------------End_of_text------ ----",当 "display_name = lo" 和 "End_of_text" 不包括在内时。
我尝试运行以下命令:
String pattern = "^\\sdisplay_name = lo\\s+(.*)---------------End_of_text---------------------";
Pattern r = Pattern.compile(pattern, Pattern.DOTALL);
Matcher m = r.matcher(interfaceData);
if (m.find()){
System.out.println("Group 0 found value: " + m.group(0) );
System.out.println("Group 1 found value: " + m.group(1) );
System.out.println("Group 2 found value: " + m.group(2) );
}
else {System.out.println("NO MATCH");}
没有匹配,我错过了什么?
解决方案
推荐阅读
- javascript - 在 NodeJS 中跟踪对象内存使用情况
- javascript - 在 Angular 6 中使用 javascript/typescript 中的现有数组创建新数组时出现不一致
- apache - 如何修复目录列表
- python - 如何解析类属性的名称?
- javascript - Vuejs 从应用程序外部更改数据 VueX 存储状态
- java - Spring 控制器、Jackson 数据格式和 Azure blob 存储 v10
- android - 发送大数据 OkHttp3 内存不足
- html - css, html - colspan 在不同的表上工作不一样
- java - 实现我自己的锻炼助手应用程序 - 集合考虑
- laravel - 如何在侧边栏中显示所有表格中的数据?