in reply to regex help, please

As SuicideJuknie points out, your substitution is failing because your regex doesn't match. I thought it was because your .+ in the middle of your pattern is 'greedy' so is matching right to the end of the string, and your Track part can't match. However this is not right because perlre tells us that

" . Match any character (except newline) "
So really it is failing because you don't have 'Track' on the same line as the 'CD_TEXT' bit.

Some playing around and I got to this, which does the job, and should get you to the answer:

use warnings; use strict; my $string = <<END; CD_DA CD_TEXT { LANGUAGE_MAP { 0: 9 } LANGUAGE 0 { TITLE "Multi-01" PERFORMER "" SIZE_INFO { 1, 1, 19, 0, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 7, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0} } } // Track 1 END ## include *all* characters between markers if ( $string =~ m|(CD_TEXT[\W\w]+)Track|){ print "\'$1\' Matched!\n"; } else { print "\'$string\' did not match...\n"; } __END__ 'CD_TEXT { LANGUAGE_MAP { 0: 9 } LANGUAGE 0 { TITLE "Multi-01" PERFORMER "" SIZE_INFO { 1, 1, 19, 0, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 7, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0} } } // ' Matched!

Hope this 'elfs.

Just a something something...

Replies are listed 'Best First'.
Re^2: regex help, please
by mchampag (Acolyte) on Dec 21, 2009 at 17:52 UTC

    It DID 'elf! Adding the ' 1\n' to force the match to stop at '// Track 1', I changed my s/// to:

    $tocfile =~ s/CD_TEXT[\W\w]+(\/\/ Track 1\n)/$1/m;

    And it's now doing what I mean. Thanks for the remedial lesson on the . metacharacter!!!

    -Matt