re = /^r\s(?P<nickname>\b\S+\b).*\n
^s\b.*?(?P<type>\bGuard\b).*\n
^v.*\n
^w\s.*?(?P<bandwidth>\b[0-9]+\b)/mx
str = 'r Tor4ever AAcif1htILdru0BO0qX7OwGVhAU oHlbWBdaN3+QSleqBVL9/yAdcRs 2014-07-31 21:42:43
s Exit Fast Guard HSDir Running V2Dir Valid
v Tor 0.2.4.21
w Bandwidth=231
p reject 25,119,135-139,445,563,1214,4661-4666,6346-6429,6699,6881-6999
r Tornin AA8YrCza5McQugiY3J4h5y4BF9g vNRd1kyQ0i9UsVwYq5YFPHJi3jw 2014-08-01 00:26:18
s Fast Guard HSDir Named Running Stable V2Dir Valid
v Tor 0.2.4.23
w Bandwidth=713
p reject 1-65535'
# 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