Since I'm not yet the regex master I aspire to be, I can't authoritatively state that this solution is better, but it seems to work.
If you're working with ordered item labels you can make your assertion more specific:
$n = 1; s/((??{$n+1})\))(?{$n++})/\n$1/g;
The first iteration matches "2)" and replaces it with "\n2)", the second "3)", and so on.
Update: I should know better than to post when I'm tired. Someone just pointed out to me that it would be much neater to do:
$n = 2; ++$n while s/$n(?=\))/\n$n/
Thanks, Aristotle, you're right. The while loop substitution isn't equivalent because it will make replacements in any order (at any position in the string) while the original substitution I posted will not.
In reply to Re: Re: Regular Expressions: Call for Examples
by converter
in thread Regular Expressions: Call for Examples
by japhy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |