作者Romulus (罗姆修复计画开始)
看板Ruby
标题[问题] 请问Ruby的正规表现式如何使用Short Matching
时间Thu Aug 28 01:14:35 2008
我现在有一个剌剌长的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
2F:→ godfat:Lazy_quantification 用 .*? 08/28 01:29