items, chunks = [], [] DATA.each_line{|line| if line[0] == "[" unless chunks.empty? # handle last chunk chunks[0].match(/\[(\w+) (\w+)\]/) items << Hash[$1, $2, *chunks.join.scan(/^(\w+)=(.+)$/).flatten] end # start new chunks chunks.clear; chunks << line else chunks << line end } p items __END__ [WORLDCHAR c_horse_gray] CREATE=033ac420 SERIAL=091600 NAME=Gray Horse TIMER=0 TAG.wexp_tot=019 NPC=1 P=1326,1341,7 DIR=0 FLAGS=048000000 ACTION=070 ACTARG1=07008f06c ACTARG2=06 HITS=100 STAM=50 MANA=9 FOOD=63 STR=100 INT=9 DEX=50 KARMA=1 Parrying=441 MagicResistance=253 Tactics=379 Taming=600 Wrestling=343 [EOF]
Standard input is empty
[{"WORLDCHAR"=>"c_horse_gray", "CREATE"=>"033ac420", "SERIAL"=>"091600", "NAME"=>"Gray Horse", "TIMER"=>"0 ", "NPC"=>"1", "P"=>"1326,1341,7", "DIR"=>"0", "FLAGS"=>"048000000", "ACTION"=>"070", "ACTARG1"=>"07008f06c", "ACTARG2"=>"06", "HITS"=>"100 ", "STAM"=>"50 ", "MANA"=>"9 ", "FOOD"=>"63 ", "STR"=>"100 ", "INT"=>"9", "DEX"=>"50", "KARMA"=>"1 ", "Parrying"=>"441", "MagicResistance"=>"253", "Tactics"=>"379", "Taming"=>"600", "Wrestling"=>"343"}]