我有以下输入数据(请注意,有些空格正在搞乱):
aggr0_howzeg253_sata online raid_dp,aggr root,diskroot, nosnap = off,raidtype = raid_dp, 32位raidsize = 14,ignore_inconsistent = off, snapmirrored = off,resyncsnaptime = 60, fs_size_fixed = off,snapshot_autodelete = on, lost_write_protect = on,ha_policy = cfo, hybrid_enabled = off,percent_snapshot_space = 5%, free_space_realloc =关
Volumes: root_vol_howzeg253, howzeg253_ixb_esx_vol16_sv_mirror, howzeg253_ixb_esx_vol5_sv_mirror, howzeg253_ixb_esx_vol18_sv_mirror, howzeg253_ixb_esx_vol21_sv_mirror, howzeg253_ixb_esx_vol33_sv_mirror, howzeg253_ixb_esx_vol24_sv_mirror, howzeg253_ixb_esx_vol34_sv_mirror Plex /aggr0_howzeg253_sata/plex0: online, normal, active RAID group /aggr0_howzeg253_sata/plex0/rg0: normal, block checksums RAID group /aggr0_howzeg253_sata/plex0/rg1: normal, block checksums
aggr1_howzeg253_sata online raid_dp,aggr nosnap = off, raidtype = raid_dp,raidsize = 14, 32位ignore_inconsistent = off,snapmirrored = off, resyncsnaptime = 60,fs_size_fixed = off, snapshot_autodelete = on,lost_write_protect = on, ha_policy = cfo,hybrid_enabled = off, percent_snapshot_space = 5%, free_space_realloc =关
Volumes: howzeg253_ixb_esx_vol6_sv_mirror, howzeg253_ixb_esx_vol17_sv_mirror, howzeg253_ixb_esx_vol7_sv_mirror, howzeg253_ixb_esx_vol19_sv_mirror, howzeg253_ixb_esx_vol23_sv_mirror, howzeg253_ixb_esx_vol8_sv_mirror, howzeg253_ixb_esx_vol36_sv_mirror Plex /aggr1_howzeg253_sata/plex0: online, normal, active RAID group /aggr1_howzeg253_sata/plex0/rg0: normal, block checksums RAID group /aggr1_howzeg253_sata/plex0/rg1: normal, block checksums
我将这个表达式用于preg_match_all:
preg_match_all("|(aggr[a-z0-9_]+)\s+.*Volumes.\s+(.*)\s+Plex.*checksums|s", $rawdata, $out);
然而,我得到的输出只给出了第一个块的信息(似乎正确解析;每个块以一行开头的aggr _...开头)。 我尝试了不同的方法,但无法得到我想要的东西(比如表达式开头的胡萝卜多线和s修饰符)。
所以这是我得到的输出:
...
[1] => Array
(
[0] => aggr4_delng153_sas_sata
)
[2] => Array
(
[0] => delng153_ixb_esx_vol19, delng153_ixb_esx_vol20,
delng153_ixb_esx_vol21, delng153_ixb_esx_vol28,
delng153_ixb_esx_vol29, delng153_ixb_esx_vol30,
delng153_ixb_esx_vol31
)
我想要返回第二个块。 任何人都可以帮助我吗?
提前致谢!
答案 0 :(得分:0)
试试这个:
preg_match_all("|(aggr[a-z0-9_]+)\s+.*Volumes.\s+(.*)\s+Plex.*checksums|sg", $rawdata, $out);
全局g
搜索标志使RegExp在整个字符串中搜索模式
答案 1 :(得分:0)
兄弟,我认为你正在寻找这个
'/(aggr[a-z0-9_]+)\s.*?Volumes:(.*?)rg1: normal, block checksums/s'
答案 2 :(得分:0)
真的很蠢,我昨天晚上找不到它。 今天早上我看了5分钟就像是:不,会发布它。 5分钟后,我发现使用修饰符U它有效。 不过,我也会研究你提出的解决方案。
似乎Naveed的答案会回归很多(阻止直到“阻止cheksums”这个词)然而我可能错了。