in reply to one line regular expression - help needed

Hello and welcome!

I think your "problem" is that <ADDRESS> and </ADDRESS> are on different lines, and -n goes through your file line by line.

Conveniently, Perl can work with line-oriented stuff quite well:

perl -i.bak -ne "print unless /<ADDRESS>/ .. m!</ADDRESS>!"

This approach only works if there is only one <ADDRESS> sequence and you want to remove that.

Your regular expression does not seem to allow for (much) whitespace between <ADDRESS> and the email address starting. If you change the following dot to \s*, you will have more success in matching. You still need to slurp the whole input at once. I think -0777 will activate slurp mode.

Replies are listed 'Best First'.
Re^2: one line regular expression - help needed
by morgon (Priest) on Jul 29, 2010 at 18:03 UTC
    In case there are several ADDRESS-sections and you want to get rid of them all in one go you can do it like this:

    perl -i.bak -0777 -pe 's|<ADDRESS>.*?</ADDRESS>||gs' <your file>
Re^2: one line regular expression - help needed
by Thalamus (Acolyte) on Jul 29, 2010 at 08:46 UTC
    Thanks for the response guys. You saved my day.