给出以下文本
bond0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
eth0: 11329920252 12554462 0 0 0 0 0 3561 13072970332 12899522 0 0 0 0 0 0
我需要捕获列值。我想到了这些行:
Regex: `(\w+):(?:\s+(\d+))+`
Php: `preg_match_all('/(\w+):(?:\s+(\d+))+/sim', $data, $regs)
但不幸的是,它只捕获第一列。
Array
(
[0] => Array
(
[0] => dummy0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[1] => bond0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[2] => eth0: 11329920252 12554462 0 0 0 0 0 3561 13072970332 12899522 0 0 0 0 0 0
[3] => ip6tnl0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[4] => lo: 51675995 100695 0 0 0 0 0 0 51675995 100695 0 0 0 0 0 0
[5] => sit0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[6] => tunl0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
)
[1] => Array
(
[0] => 0
[1] => 0
[2] => 0
[3] => 0
[4] => 0
[5] => 0
[6] => 0
)
)
有什么建议吗?谢谢`
====编辑==== 只是要清楚一点:我知道我可以preg_match
搜索\d+
值或将整个字符串分成几行并在每一行上运行explode,但我对我有第一列的正则表达式解决方案感兴趣作为结果数组的第一个成员(实际上忘记在问题的初稿中放置捕获大括号),并在后面的列中包含数据,每一行都放在它的专用数组中......