Web ページから競走馬の名前を解析する単純な Ruby スクリプトに取り組んでいます。この正規表現はhttp://rubular.com/で動作しますが、スクリプトを実行しても何も出力されません。
require 'open-uri';
url = "http://www.bloodhorse.com/horse-racing/race/race-results";
connection = open(url);
content = connection.read;
if(content =~ /(<span class="horseName">)(\n)(.*?)(\>)(.*?)(<\/a>)/)
print $5,"\n";
end
ページのソースの例は次のとおりです。
<li value="2">
<span class="horseName">
<a href="/horse-racing/thoroughbred/felonious-fred/2010">Felonious Fred</a>
したがって、私のスクリプトは一致する Regex の 5 番目のキャプチャを返す必要があると思います。この場合は「Felonious Fred」である必要があります。私は何を間違っていますか?