这是一个非常简单的问题,但很少使用正则表达式,所以我很抱歉。我正在为一些简单的 UBBcodes 编写一个简单的视图助手
我希望能够打电话:
<%=arc_format "[quote]hello you from me[\quote]" %>
并让它返回:
<div class='start-quote'>
hello you from me
</div>
我的帮手:
def arc_format str
str=str.gsub(/\[quote\]/,'<div class="start-quote">') # works but adds in second quote; seems to hit off second isntance
str=str.gsub!(/\[\\quote\]/,'</div>')
str.html_safe
end
输出是
<div class='start-quote'>
hello you from me
<div class='start-quote'>
</div>
如何从不替换中获得第二个正则表达式?
提前谢谢