繁体   English   中英

无论中间内容如何如何选择特定行

[英]How to select specific lines regardless on the content in the middle

让我们从我拥有的结构开始,以便我可以更好地解释我想做什么。 想象一下,我有一条文本如下:

write information1/info_a/content
read information/content
write information1/info_b/content
write information1/info_c/content
write information2/info_a/content
write information2/info_b/content
write information3/format/info_b/content

我想突出显示以特定路径开头并且还包含另一条路径的每一行,例如:

  • 以'write'开头
  • 并包含“ info_b”

然后,上面给出示例的期望输出为:

write information1/info_b/content
write information2/info_b/content
write information3/format/info_b/content

如何使用正则表达式执行此操作?

预先感谢大家

我知道对于选择以regex开头的所有内容,我都可以做到:

^写

在说到行尾之前,我应该使用键$

您可以使用正则表达式选择包含“ info_b”的任何行:

^write.*info_b.*$

转换为行开始->任何数量的东西-> info_b->任何数量的东西->结束行

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM