use strict;
my $str = 'Error
at Logger._s (/var/user/impl/lib/log.js:7:17)
at Logger.I (/var/user/impl/lib/log.js:26:22)
at getWxContext (/var/user/impl/route.js:136:7)
at route (/var/user/impl/route.js:19:13)
at EventHandler.exports.main [as realHandler] (/var/user/index.js:14:22)
at EventHandler.handle (/var/runtime/node8/bootstrap.js:401:28)
at invoke (/var/runtime/node8/bootstrap.js:204:22)
at Timeout.setTimeout [as _onTimeout] (/var/runtime/node8/bootstrap.js:133:9)
at ontimeout (timers.js:475:11)
at tryOnTimeout (timers.js:310:5)';
my $regex = qr/.*at \w+\.[A-Z] \(.+\n([\s\S]+\n)*.*(\[as realHandler]|<anonymous>)/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