Regex Named Captures in Ruby
RubyUse named captures and MatchData to extract fields.
text = "user=chris id=42"
if m = text.match(/user=(?<user>\w+)\s+id=(?<id>\d+)/)
puts "user: #{m[:user]}"
puts "id: #{m[:id]}"
end
Use named captures and MatchData to extract fields.
text = "user=chris id=42"
if m = text.match(/user=(?<user>\w+)\s+id=(?<id>\d+)/)
puts "user: #{m[:user]}"
puts "id: #{m[:id]}"
end