パンくず
書籍 Regular Expressions Cookbook
Replace All Matches Within the Matches of Another Regex
サンプル
# タグの中の文字列がbeforeだった場合のみ置換する subject = "<b>before</b>" innerre = /before/ result = subject.gsub(/<b>.*?<\/b>/) {|match| match.gsub(innerre, 'after') } pp result #=>"<b>after</b>"