これは本当に簡単な質問ですが、正規表現を使用することはめったにないので、お詫び申し上げます。いくつかの単純な UBBcode 用の単純なビュー ヘルパーを作成しています。
私は呼び出すことができるようにしたい:
<%=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>
2番目の正規表現を置き換えないで取得するにはどうすればよいですか?
thx事前に