use strict;
my $str = 'General
Complete name : C:\\Projects\\Foray\\MediaEngine\\SampleMedia\\flv\\small.flv
Format : Flash Video
File size : 296 KiB
Duration : 5s 560ms
Overall bit rate mode : Variable
Overall bit rate : 436 Kbps
Writing application : Lavf52.103.0
Video
Format : Sorenson Spark
Codec ID : 2
Duration : 5s 560ms
Bit rate : 781 Kbps
Width : 320 pixels
Height : 240 pixels
Display aspect ratio : 4:3
Frame rate mode : Constant
Frame rate : 25.000 fps
Bit depth : 8 bits
Bits/(Pixel*Frame) : 0.407
Stream size : 530 KiB
Audio
Format : MPEG Audio
Format version : Version 1
Format profile : Layer 3
Codec ID : 2
Codec ID/Hint : MP3
Duration : 5s 512ms
Bit rate mode : Variable
Bit rate : 63.8 Kbps
Channel(s) : 1 channel
Sampling rate : 44.1 KHz
Compression mode : Lossy
Stream size : 42.9 KiB (14%)
';
my $regex = qr/(?mis)^\bgeneral( #[0-9])?(.*?)^\s*$/p;
if ( $str =~ /$regex/ ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Perl, please visit: http://perldoc.perl.org/perlre.html