Skip to content

Instantly share code, notes, and snippets.

@FiXato
Created January 28, 2013 21:42
Show Gist options
  • Save FiXato/4659362 to your computer and use it in GitHub Desktop.
Save FiXato/4659362 to your computer and use it in GitHub Desktop.
Something for Unknown_Entity aka o_o
#!/usr/bin/env ruby
#encoding: utf-8
msgs = [
"[1-7] Porto Mojada: Foxtrot Tango [Work your alphabets]",
"[SOLVED: TATTOO] [1-9] Topless Beach: Boxstep [Gathering Data. Keyword: Boxing]",
"[SOLVED: SYLVESTER] [2-2] Video Store: Harold's Puzzle"
]
regexp = /(\[SOLVED: (?<solution>.+?)\] )?\[(?<num1>\d+)(-(?<num2>\d+))?\] (?<title>.+?)( \[(?<hint>.+?)\])?\z/
msgs.each{|msg| puts msg.match(regexp).inspect}
#<MatchData "[1-7] Porto Mojada: Foxtrot Tango [Work your alphabets]" solution:nil num1:"1" num2:"7" title:"Porto Mojada: Foxtrot Tango" hint:"Work your alphabets">
#<MatchData "[SOLVED: TATTOO] [1-9] Topless Beach: Boxstep [Gathering Data. Keyword: Boxing]" solution:"TATTOO" num1:"1" num2:"9" title:"Topless Beach: Boxstep" hint:"Gathering Data. Keyword: Boxing">
#<MatchData "[SOLVED: SYLVESTER] [2-2] Video Store: Harold's Puzzle" solution:"SYLVESTER" num1:"2" num2:"2" title:"Video Store: Harold's Puzzle" hint:nil>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment