[英]Regular Expression : Multiline check problem
你好,我有這個正則表達式的問題
!
interface TenGigabitEthernet 1/49
description Uplink
no ip address
switchport
no shutdown
!
interface TenGigabitEthernet 1/50
no ip address
shutdown
!
interface TenGigabitEthernet 1/51
no ip address
shutdown
!
我嘗試了這個regexp(接口)((。 \\ s。 )+)但它不起作用,因為它匹配“接口”和其余的文本
我需要抓住第一組“界面”,在第二組我需要所有直到第一次出現“!” 例如:第一組:
interface
第二組:
TenGigabitEthernet 1/51
no ip address
shutdown
我怎么能這樣做?
如果內容本身可以包含一個!
,你可以查一下!
在行的開頭重復匹配所有行,直到遇到!
在開始時。
^(interface)\s*(.*(?:\n(?!!).*)*)
在Java中
String regex = "^(interface)\\s*(.*(?:\\n(?!!).*)*)";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.