use strict;
my $str = '
xwininfo: Window id: 0x4800024 "Yebe"
Absolute upper-left X: 100
Absolute upper-left Y: 164
Relative upper-left X: 10
Relative upper-left Y: 45
Width: 1600
Height: 1200
Depth: 24
Visual: 0x6e
Visual Class: DirectColor
Border width: 0
Class: InputOutput
Colormap: 0x4800022 (not installed)
Bit Gravity State: ForgetGravity
Window Gravity State: NorthWestGravity
Backing Store State: NotUseful
Save Under State: no
Map State: IsViewable
Override Redirect State: no
Corners: +100+164 -860+164 -860-76 +100-76
-geometry 1600x1200+90-66';
my $regex = qr/.+left X:..(.+?)\n.+Y:..(.+?)\n.+\n.+\n.+:.(.+?)\n.+:.(.+?)\n/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