Skip to content

Instantly share code, notes, and snippets.

@plexus
Created June 12, 2014 06:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plexus/9a9ee2e00a4f80f826a1 to your computer and use it in GitHub Desktop.
Save plexus/9a9ee2e00a4f80f826a1 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
require 'open-uri'
#txt = open('https://raw.githubusercontent.com/openfootball/world-cup/master/2014--brazil/cup.txt').read
txt = open('https://raw.githubusercontent.com/openfootball/world-cup/master/2010--south-africa/cup.txt').read
# (1) Fri Jun/11 16:00 South Africa 1-1 Mexico @ Soccer City, Johannesburg
# (1) Thu Jun/12 17:00 Brazil - Croatia @ Arena de São Paulo, São Paulo (UTC-3)
regex = %r{
\( (?<number> \d+ ) \) \s+
(?<day_of_week> \w+ ) \s+
(?<month> \w+ ) /
(?<day_of_month> \d+ ) \s+
(?<hour> \d+ ) :
(?<minute> \d+ ) \s+
(?<team_a> \w+ ) \s+
( (?<score_a> \d+) )? \s*-\s*
( (?<score_b> \d+) )? \s+
(?<team_b> \w+ ) \s*@\s*
(?<location> .*)
(\(UTC(?<utc_offset>[+-]\d+)\))?
}x
txt.each_line do |line|
m = regex.match(line)
p m if m
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment