Re: [問題] 請問字串比對問題

看板Perl作者時間16年前 (2009/06/03 20:46), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/3 (看更多)
※ 引述《frekohmygod (ㄚ助)》之銘言: : <td align=center nowrap class='wuc9'>買進價</td><td align=center nowrap : class='wuc9'>賣出價</td><td align=center nowrap class='wuc9'>成交價</td> : 上列是我所欲抓取網頁的原始碼 : 現在的問題是只能抓取到"買進價" : 請問要如何寫字串比對才能出現"買進價" : "賣出價" : "成交價" : 這是目前為止的進度, while(<File>=~ m/uc9\'\>(.+?)\</) : { : print $1."\n"; : print $2."\n"; : } : 請問哪裡出了問題? 謝謝指教~ 可以試看看用 @matches = ($str =~ m/PATTERN/g) 的方式來全部比對。 ---------------------------------------------------------------------------- #!/usr/bin/perl use strict; use warnings; my $str = q{<td align=center nowrap class='wuc9'>買進價</td><td align=center nowrap class='wuc9'>賣出價</td><td align=center nowrap class='wuc9'>成交價 </td>}; my $pattern = qr/<td.+?>(.+?)<\/td>/; my @matches = ($str =~ m/$pattern/g); my $i = 0; print ++$i, "[$_]\n" foreach (@matches); -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 203.67.65.200
文章代碼(AID): #1A9d2oQt (Perl)
討論串 (同標題文章)
文章代碼(AID): #1A9d2oQt (Perl)