[問題] 請問Ruby的正規表現式如何使用Shortest Ma …
我現在有一個剌剌長的html file
我要把其中的<a href="....">TEXT</a>都換成[[TEXT]]
我想用regular expression來作,可是因為String.gsub!用的都是longest matching,
所以如果本文是:
<a href="...">TEXT1</a>
<a href="...">TEXT2</a>
下txt.gsub!(%r{<a href=.*>(.*)</a>}, '[[\+]]')
就會只剩下[[TEXT2]],TEXT1不見了
請問有辦法在Ruby裡面使用shortest matching嗎?
--
聽說把blog分類比較有人看 ._.a
遊戲blog http://rogametalk.blogspot.com/
主(雜)blog http://urakagi.blogspot.com/
日文blog http://urakagij.blogspot.com/
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.134.115.122
推
08/28 01:29, , 1F
08/28 01:29, 1F
→
08/28 01:29, , 2F
08/28 01:29, 2F
Ruby 近期熱門文章
PTT數位生活區 即時熱門文章