Instead of doing a split, doing line by line processing makes more sense. Just create a single regex to detect what looks like a continued line to you.
Outputswhile (<DATA>) { chomp; # Continued Line if (/^\s+(.*)(?<!:)$/) { print " $1"; # New Line } else { print "\n" if $. > 1; print $_; } } print "\n"; __DATA__ Into the little hill 2-osainen lyyrinen tarina sopraanolle, altolle seka viidelletoista soittajalle 1. OSA (01-05) /20:28: 01 1. The crowd (Kill them they bite, kill them they steal -) /0:50. 02 2. The minister and the crowd (The minister greets the crowd -) /2:50. 03 3. The crowd (Kill them they bite, kill them they steal -) /1:42. 04 4. The minister and the stranger (Night comes but not sleep -) /8:33. 05 5. Interlude - Mother and child (Why must the rats die, Mummy? -) /6:33. 2. OSA (06-08) /16:34: 06 6. Inside the minister's head (Under a clear sky, the minister steps from the limousine -) /3:43. 07 7. The minister and the stranger (His head lies on his desk, between the family photograph -) /5:52. 08 8. Interlude - Mother(s) and child(ren) (Each cradle rocks empty -) /6:59. 3. OSA BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH (09-10) /14:14: 09 9. Another very long stupid song title to be used as yet another dumb example /6:66. 10 10. Last fictive song title /6:66.
Into the little hill 2-osainen lyyrinen tarina sopraanolle, altolle seka viidelletoista soittajalle 1. OSA (01-05) /20:28: 01 1. The crowd (Kill them they bite, kill them they steal -) /0:50. 02 2. The minister and the crowd (The minister greets the crowd -) /2 +:50. 03 3. The crowd (Kill them they bite, kill them they steal -) /1:42. 04 4. The minister and the stranger (Night comes but not sleep -) /8: +33. 05 5. Interlude - Mother and child (Why must the rats die, Mummy? -) +/6:33. 2. OSA (06-08) /16:34: 06 6. Inside the minister's head (Under a clear sky, the minister ste +ps from the limousine -) /3:43. 07 7. The minister and the stranger (His head lies on his desk, betwe +en the family photograph -) /5:52. 08 8. Interlude - Mother(s) and child(ren) (Each cradle rocks empty - +) /6:59. 3. OSA BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLA +H BLAH BLAH BLAH (09-10) /14:14: 09 9. Another very long stupid song title to be used as yet another d +umb exampl e /6:66. 10 10. Last fictive song title /6:66.
However, I do see one problem with your stated logic after '08' in your sample date, as I suspect you want the following to appear on its own line:
The following looks closer to what you want.3. OSA BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH + BLAH BLAH (09-10) /14:14:
Outputswhile (<DATA>) { chomp; # Continued Line if (/^(?>\s+)(?!\d+\.)(.*)$/) { print " $1"; # New Line } else { print "\n" if $. > 1; print $_; } } print "\n";
Into the little hill 2-osainen lyyrinen tarina sopraanolle, altolle seka viidelletoista soittajalle 1. OSA (01-05) /20:28: 01 1. The crowd (Kill them they bite, kill them they steal -) /0:50. 02 2. The minister and the crowd (The minister greets the crowd -) /2 +:50. 03 3. The crowd (Kill them they bite, kill them they steal -) /1:42. 04 4. The minister and the stranger (Night comes but not sleep -) /8: +33. 05 5. Interlude - Mother and child (Why must the rats die, Mummy? -) +/6:33. 2. OSA (06-08) /16:34: 06 6. Inside the minister's head (Under a clear sky, the minister ste +ps from the limousine -) /3:43. 07 7. The minister and the stranger (His head lies on his desk, betwe +en the family photograph -) /5:52. 08 8. Interlude - Mother(s) and child(ren) (Each cradle rocks empty - +) /6:59. 3. OSA BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH + BLAH BLAH (09-10) /14:14: 09 9. Another very long stupid song title to be used as yet another d +umb example /6:66. 10 10. Last fictive song title /6:66.
In reply to Re: Complex regex with negated group
by wind
in thread Complex regex with negated group
by december
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |