Created
May 5, 2025 01:17
-
-
Save fumikito/f2a252c8b582026dfa061950c9ef711f to your computer and use it in GitHub Desktop.
<ruby>タグの変換に失敗したのでrtタグを含まないrubyタグを正規表現で除去する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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