1) 解析対象の例をいくつか使用できます。
2) 式の最後に「x」を使用する場合、正規表現に空白とコメントを入れて、よりわかりやすくすることができます
3) また、分解すると、( ) 内のものの 2 番目の部分が数字の一致を欠いていることに気付くでしょう... 代わりに、0 以上の '_' を探し、数字を見たときに分割します、したがって一致しません。
while(<TOCFILE>)
{
$toc_line = $_;
$toc_line =~
s/ # replace the follwoing
<inlineFig # match this text
.*? # then any characters until the next sequence matches
( # throw the match into $1
\.\.\/pics\/ch09_inline99_ # ..\pics\cho9_inline99_
\d*?\.jpg # folowed by 0 or more numbers
)*? # keeping doing that until the next sequence matches
<\/inlineFig> # match this text
/ # with the follwoing
<img src="${1}" alt="" \/\> # some text and the result of $1 above.
/xg; # <- the x makes it ignore whitespace and #comments
$new_toc_file .= $toc_line;
}
4) 前述のとおり、()*? $1 に最後に一致したもののみを返しますが、入力が特定の形式のみである場合、これは問題にはなりません。