Regex with multiple lines before end line -
hello guys have question, have string this:
interface gigabitethernet0/3/0/0 description physicalinterface ! interface gigabitethernet0/3/0/0.100 description vlan100 dot1q vlan 100 ! multicast-routing address-family ipv4 interface tengige0/2/0/0.3880 ! disable interface under multicast-routing section: disable ! router static address-family ipv4 unicast gigabitethernet0/3/1/4.3999 192.168.100.105 so use select between: interface , ! like:
interface gigabitethernet0/3/0/0 description physicalinterface ! interface gigabitethernet0/3/0/0.100 description vlan100 dot1q vlan 100 ! interface tengige0/2/0/0.3880 ! i have tried many different ways:
interface(.*?)\n (interface(.*?)|\n{2,}) etc(i have forgotten every other ways) recommend guys?
in order match text including newlines between 2 strings, need use lazy dot matching technique dotall (or in other terminology, singleline) modifier: .*?.
when using pcre regex patterns (sublimetext uses regex flavor), can use inline version of modifier: (?s).
lazy dot matching ensures match between start , leftmost end boundary. 1 q matched in 1 q 4q 1.*?q pattern. greedy matching, 1.*q, match whole string.
so, in case, can use following regex:
(?s)interface.*?! |1 | 2 |3|4 here,
- the inline dotall modifier
- starting boundary, literal
interfacestring - lazy dot maching construct
- literal
!end boundary
Comments
Post a Comment