Created
November 9, 2012 10:30
-
-
Save tengla/4045046 to your computer and use it in GitHub Desktop.
Named regexp in Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby -w | |
r = %r{name:(?<name>[A-Za-z]+);age:(?<age>\d+);location:(?<location>\w+)}x | |
DATA.read.split("\n").each do |row| | |
res = r.match(row) | |
puts res[:name] + " " + res[:age] + " " + res[:location] | |
end | |
__END__ | |
name:John;age:26;location:Stockholm | |
name:Jane;age:25;location:Copenhagen | |
name:Minnie;age:5;location:Oslo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment