re = /(?:\d+\s+)(\w+)(?:\s+)(\w+)/m
str = ' Id Name State
----------------------------------------------------
14 vm2 running
19 vm7 running
22 vm10 running
27 vm11 running
36 vm9 running
38 vm12 running
43 vm6 running
46 vm1 running
49 vm4 running
63 vm5 running
65 vm8 running
67 vm3 running
'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html