in reply to regex help, please

In what way is it not working?

Is it running too slowly because the greedy .+ first tries to match the entire file, and then tries the entire file-1, and so on?

Is it removing too much because there is a second // Track in the file that it can match?

Is it removing too little because one of your titles/performers happens to include the sequence // Track (while trying a non-greedy ".+?")?

Without getting into real parsing, I'd suggest starting with a non-greedy +. Match explicitly against the closing bracket and the newlines to reduce (unfortunately not eliminate) the chances of matching something you don't expect, and move the actual // Track check into a lookahead, so that it is not part of the match and won't be deleted. (Also, lookaheads are good to learn for the future)

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

    The regex apparently isn't matching anything. If I print $tocfile, the CD_TEXT field is still there.

    I can see I have some book larnin ahead of me. Thanks for the tip about lookaheads.