实现匹配位置的最佳方法是什么(由=~
)对于使用时的每场比赛gsub
or scan
?
"hello".gsub(/./) { Regexp.last_match.offset(0).first }
=> "01234"
See 正则表达式.last_match http://www.ruby-doc.org/core-1.9.3/Regexp.html#method-c-last_match and 匹配数据 http://www.ruby-doc.org/core-1.9.3/MatchData.html.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)