From: Mirco Wahab on
Deepan Perl XML Parser wrote:
> Now i want to get everything between "<text><![CDATA[" and "]]></
> text>" [ie i need to capture the CDATA section]and i am using the
> below code
>
> if( $str =~ m#<text><!\[CDATA\[(.*)\]\]></text># )
> {
> print $1;
> }

Your expression is (besides the /s modifier) perfectly valid
but I'd like to make an additional remark. You could strip
the newline characters (if any) and extract more than one
CDATA section, sth. like:

my $reg = qr{
<text> # find section <text>
<!\[CDATA\[ [\r\n]? # which contains another CDATA section
(.+?) # capture the CDATA lines but ?check? \]\]
[\r\n]?\]\]> # until CDATA terminator
</text> # maybe even the <text> is closed properly
}sx;

print $1 while $str =~ /$reg/g; # extract each CDATA section

Regards

M.