-5

I have a disclaimer message in an email which I want to remove using Perl.

The code is below:

my $stval = 'hii This is a test Email*************** CAUTION - Disclaimer *****************
        This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely
        for the use of the addressee(s). If you are not the intended recipient, please
        notify the sender by e-mail and delete the original message.
        ******MAILEND***** End of Disclaimer ******MAILEND*****';

$stval =~ s/[*]//g;    # this removes all * Characters
print "$stval\n\n";

The output I am expecting should be as below:

hii This is a test Email
4
  • And what it the Output you get?
    – Jens
    Apr 21, 2015 at 17:45
  • That just removes asterisks.
    – tadman
    Apr 21, 2015 at 17:45
  • try this print $1 if($stval=~/([a-zA-Z \s]*)*/); Apr 21, 2015 at 17:54
  • As the comment says, s/[*]//g “removes all * characters”. What did you want to do? No one can help unless you can describe precisely what part of the text you want to remove
    – Borodin
    Apr 21, 2015 at 17:56

2 Answers 2

0

That scalar string has several embedded \n, as if it is a here document. You can remove everything from the first '*' to the end of the string with:

$stval =~ s/[*\n]+.+//g;    # this removes all * Characters
2
  • But can you suggest if i have to remove from 'CAUTION' text onward what can be the option. The reason why i am asking is if there is any * character in the mail then it will remove the text after that as well. Apr 22, 2015 at 7:48
  • my $stvalcopy = $stval; print "$stval\n\n"; $stval =~ s/[*\n]+.+//g; # this removes all * Characters print "$stval\n\n"; print "$stvalcopy\n\n"; $stvalcopy =~ s/\s+Caution.*//is; # this removes ' Caution' + all Characters print "$stvalcopy\n\n"; print "Programming Perl (3rd) Chapter 5: Pattern Matching is must read/learn if you intend to stay with Perl\n";
    – perlboy
    Apr 22, 2015 at 17:16
-1

Use s modifier to include newline in the deletion:

$stval =~ s/\*{10}.*//s;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.