Hi,

I have a file like below : -

BEGIN:VCARD
VERSION:2.1
EMAIL:te...@test.com
FN:test1
REV:20101116T030833Z
UID:644938456.1419.
END:VCARD

>From <>(S_______-000000000003) Tue Nov 16 03:10:15 2010
content-class: urn:content-classes:person
Date: Tue, 16 Nov 2010 11:10:15 +0800
Subject: test
Message-ID: <644938507.1420>
MIME-Version: 1.0
Content-Type: text/x-vcard; charset="utf-8"

BEGIN:VCARD
VERSION:2.1
EMAIL:te...@test.com
FN:test2
REV:20101116T031015Z
UID:644938507.1420
END:VCARD



My requirement is to get all text between BEGIN:VCARD and END:VCARD and all
the instances. So o/p should be :-

BEGIN:VCARD
VERSION:2.1
EMAIL:te...@test.com
FN:test1
REV:20101116T030833Z
UID:644938456.1419.
END:VCARD

BEGIN:VCARD
VERSION:2.1
EMAIL:te...@test.com
FN:test2
REV:20101116T031015Z
UID:644938507.1420
END:VCARD

I am using below regex  :-

my $fh = IO::File->new("$file", "r");
my $script = do { local $/; <$fh> };
                                close $fh;
                                if (
                                   $script =~ m/
                                        (^BEGIN:VCARD\s*(.*)
                                        ^END:VCARD\s+)/sgmix
                                ){
                                print OUTFILE $1."\n";
                                }

However it just prints 1st instance and not all.

Any suggestions ?

Regards,
Punit

Reply via email to