我有一个 ruby 多行字符串(称为 efixes),如下所示:
ID STATE LABEL INSTALL TIME UPDATED BY ABSTRACT
=== ===== ========== ================= ========== ======================================
1 S hayo32.02 xxxxxxx xxxxxxxx xxxxxxxxxxxxxxx
2 S 23434.23 xxxxxxx xxxxxxxx xxxxxxxxxxxxxxx
STATE codes:
S = STABLE
M = MOUNTED
U = UNMOUNTED
Q = REBOOT REQUIRED
B = BROKEN
I = INSTALLING
R = REMOVING
T = TESTED
P = PATCHED
N = NOT PATCHED
SP = STABLE + PATCHED
SN = STABLE + NOT PATCHED
QP = BOOT IMAGE MODIFIED + PATCHED
QN = BOOT IMAGE MODIFIED + NOT PATCHED
RQ = REMOVING + REBOOT REQUIRED
我只想显示以数字开头的行。我有问题,它似乎不匹配。我在这里找到了这个解决方案,(我现在并不真正理解):
efixes_array = efixes.split("\n").select{|x| /\A[0-9]/.match(x)}
io.puts efixes_array.collect{|x| x.scan(/\A[0-9]/)}.flatten
它只匹配数字。我想显示整行。最终结果,我想显示“标签”列下的内容。