re = /^(\/dev\/(sdf|xvd)[a-p][0-9]{0,1})\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\%\s+([^\n]*)$/im
str = '/dev/xvda1 7.8G 1.1G 6.4G 14% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
udev 284M 12K 284M 1% /dev
tmpfs 59M 192K 59M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 295M 0 295M 0% /run/shm
none 100M 0 100M 0% /run/user
/dev/xvdf 20G 102M 19G 1% /mnt/data
'
# Print the match result
str.match(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