python multiline group regex
I'm trying to extract the mpath name "DS4800_VG_STAGE*" and the number of online paths from the output of multipath -ll.
DS4800_VG_STAGE_2 (3600a0b80004710ce00001ce24e08ce1c) dm-6 IBM,1815 FAStT
[size=241G][features=1 queue_i开发者_StackOverflow社区f_no_path][hwhandler=1 rdac][rw] \_ round-robin 0 [prio=100][active] \_ 1:0:1:5 sdc 8:32 [active][ready] \_ round-robin 0 [prio=0][enabled] \_ 2:0:1:5 sdf 8:80 [active][ghost] DS4800_VG_STAGE_1 (3600a0b80004706be00001ece4e08ca4f) dm-8 IBM,1815 FAStT [size=24112G][features=1 queue_if_no_path][hwhandler=1 rdac][rw] \_ round-robin 0 [prio=100][active] \_ 1:0:1:5 sdc 8:32 [active][ready] \_ round-robin 0 [prio=0][enabled] \_ 2:0:1:5 sdf 8:80 [active][ghost]
I've managed to extract the path name but am struggling with collecting the rest of the multiline output into a single group so I can process how many paths are on-line in group2.
^(\w+\s+).+?$$((?:[^\\\\]+\n+)+)
Match1:
Group 1 = "DS4800_VG_STAGE_2"
Group 2 = "[size=241G][features=1 queue_if_no_path][hwhandler=1 rdac][rw]"
Match2:
Group 1 = "DS4800_VG_STAGE_1"
Group 2 = "[size=24112G][features=1 queue_if_no_path][hwhandler=1 rdac][rw]"
Any help would be really appreciated.
Thanks in advance
Try using this instead:
^(\w+\s+).+?$$\n((?:.+?\n+)+)
I think in your expression you are using [^\\] which is preventing any line with backslash from being caught in the expression. But every line (following the first two "header lines") starts with a backslash.
精彩评论