|
Prev: FAQ 8.11 How do I decode encrypted password files?
Next: mismatch between Perl 5.6 and Perl 5.8 in printing high precision values.
From: Mirco Wahab on 2 Apr 2008 03:44 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. |