0
我有一個紅寶石多行字符串(稱爲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
它只匹配數字。我想顯示整個行。最終的結果是,我想顯示「LABELS」欄下的內容。
謝謝,我明白了。我使用下面的代碼:'efixes_array.each do | line |如果行=〜/ \ A [0-9]/io.puts行結束' – awojo 2012-08-10 13:24:22