Skip to content

Instantly share code, notes, and snippets.

@fumikito
Created May 5, 2025 01:17
Show Gist options
  • Save fumikito/f2a252c8b582026dfa061950c9ef711f to your computer and use it in GitHub Desktop.
Save fumikito/f2a252c8b582026dfa061950c9ef711f to your computer and use it in GitHub Desktop.
<ruby>タグの変換に失敗したのでrtタグを含まないrubyタグを正規表現で除去する
<?php
// ((?:(?!<rt\b)[\s\S])*?) の解説
// ((?:(?!<rt\b)[\s\S])*?)
// [\s\S] 任意の1文字
// (?!<rt\b) 否定先読み言明=直後に <rt が続かない
// (?: … ) キャプチャをスキップ(カッコ内[\s\S]で1文字ずつ読んでるので、どんどん増えてくのを抑制、なくてもよい)
$pattern = '/<ruby\b[^>]*>((?:(?!<rt\b)[\s\S])*?)<\/ruby>/i';
$html = preg_replace( $pattern, '$1', $html );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment