需要帮助使用正则表达式来选择多行。从我迄今为止它的工作,直到我把最后一个正则表达式。一旦我这样做,它跳过中间的一个。出于安全目的,密码已被删除。正则表达式多个过滤器
我的目标
- 选择位于在 版本结束当前配置开始的所有行“或!右侧前”
- 选择的所有生产线的“秘密”
- 选择所有行带“密码”
我的正则表达式
(?s)Current configuration (.*)NVRAM|secret 5 +(\S+)|password 7 +(\S+)
编辑:使用前后的空间|它似乎突出了我想要的东西。尽管如此,它并没有完成整个行。
测试数据
Building configuration...
Current configuration : 45617 bytes
!
! Last configuration change at 00:22:36 UTC Sun Jan 22 2017 by user
! NVRAM config last updated at 00:22:43 UTC Sun Jan 22 2017 by user
!
version 15.0
no service pad
!
no logging console
enable secret 5 ***encrypted password***
!
username admin privilege 15 password 7 ***encrypted password***
username sadmin privilege 15 secret 5 ***encrypted password***
aaa new-model
!
ip ftp username ***encrypted password***
ip ftp password 7 ***encrypted password***
ip ssh version 2
!
line con 0
password 7 ***encrypted password***
login authentication maint
line vty 0 4
password 7 ***encrypted password***
length 0
transport input ssh
line vty 5 15
password 7 ***encrypted password***
transport input ssh
!
所需的结果:
Building configuration...
!
version 15.0
no service pad
!
no logging console
enable
!
username admin privilege 15
username gisadmin privilege 15
aaa new-model
!
ip ftp username cfgftp
ip ftp
ip ssh version 2
!
line con 0
login authentication maint
line vty 0 4
length 0
transport input ssh
line vty 5 15
transport input ssh
!
您使用的是全球性的?它似乎工作如何你有它,如果你使用全球标志https://regex101.com/r/TyT1Mp/1 – maksymiuk
你尝试没有正则表达式? – Saksow
用'(。*?)替换'(。*)')' –