1) could use some examples of what you are analyzing.
2) if you use "x" at the end of the expression, you can put white space and comments in the regular expression to make it more understandable
3) In addition, breaking it, you will notice that in the second part of the content inside () there was no coincidence of numbers ... instead of looking for 0 or more '_' and breaking when it saw numbers, therefore it did not match.
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;
4), as already mentioned, () *? returns only the last match at $ 1, but this should not be a problem if your input will be only of a certain format.
source share