@eniehack こうしてみた。
html = %Q!<?xml version="1.0" encoding="utf-8"?><html lang="ja" prefix="og: https://ogp.me/ns#" xml:lang="ja" xmlns="http://www.w3.org/1999/xhtml"><head><title>Hello</title></head><body><div class="sect1">\n<h2 id="lorem_ipsum">lorem ipsum</h2>\n<div class="sectionbody">\n<div class="paragraph">\n<p>lorem ipsum</p>\n</div>\n</div>\n</div></body></html>!
html.gsub(%r!<div class="sect[0-9]*">(.*?)(\n</div>){3}!m, %Q!<section><h1>hello</h1>this is body</section>!)
@eniehack 最終行に改行入るけど、ヒアドキュメントの方が楽かな(脱線)
html = <<EOS
<?xml version="1.0" encoding="utf-8"?><html lang="ja" prefix="og: https://ogp.me/ns#" xml:lang="ja" xmlns="http://www.w3.org/1999/xhtml"><head><title>Hello</title></head><body><div class="sect1">
<h2 id="lorem_ipsum">lorem ipsum</h2>
<div class="sectionbody">
<div class="paragraph">
<p>lorem ipsum</p>
</div>
</div>
</div></body></html>
EOS
@eniehack 私はRubyの文法好きですねー。ストレスなく楽しく書ける。
実行前にエラーを潰しきれないのがツライので、自分の新規開発はCrystal使ってますがw
@eniehack
正規表現にmがないから . が\nにマッチしない、かな。