パンくず
書籍 Regular Expressions Cookbook
Insert the Regex Match into the Replacement Text
概要
マッチングした内容を後方参照で置換文字列内に埋め込む方法について
構文
マッチ内容全体を参照
\0
サンプル
URLをはてな記法のリンクにします。
# \Sは非空白文字。\0はマッチした文字列全体を取得 puts "http://google.com".gsub(/http:\S+/,'[\0:title=\0]')