use strict;
my $str = '<?php
namespace Application;
use Laminas\\Router\\Http\\Literal;
use Laminas\\Router\\Http\\Segment;
use Laminas\\ServiceManager\\Factory\\InvokableFactory;
return [
\'view_manager\' => [
\'template_path_stack\' => [
__DIR__ . \'/../view\',
__DIR__ . \'/../view/Application/_shared\'
],
],
\'controllers\' => [
\'factories\' => [
dsdsa
]
],
\'service_manager\' => [
\'factories\' => [
\'UsersTableGateway\' => function ($sm) {
$dbAdapter = $sm->get(\'Laminas\\Db\\Adapter\\Adapter\');
$resultSetPrototype = new \\Laminas\\Db\\ResultSet\\ResultSet();
//get base url from config
$config = $sm->get(\'Config\');
$baseUrl = $config[\'view_manager\'][\'base_url\'];
//pass base url via cnstructor to the User class
$resultSetPrototype->setArrayObjectPrototype(new Model\\Rowset\\User($baseUrl));
return new Utils\\TableGateway(\'users\', $dbAdapter, null, $resultSetPrototype);
},
\'Application\\Model\\UsersTable\' => function($sm) {
$tableGateway = $sm->get(\'UsersTableGateway\');
$table = new Model\\UsersTable($tableGateway);
return $table;
},
Utils\\Authentication::class => function($sm) {
$auth = new Utils\\Authentication(
$sm->get(\\Laminas\\Db\\Adapter\\Adapter::class),
$sm->get(Utils\\Adapter::class)
);
return $auth;
},
Utils\\Helper::class => InvokableFactory::class,
SessionManager::class => function ($container) {
$config = $container->get(\'config\');
$session = $config[\'session\'];
$sessionConfig = new $session[\'config\'][\'class\']();
$sessionConfig->setOptions($session[\'config\'][\'options\']);
$sessionManager = new Session\\SessionManager(
$sessionConfig,
new $session[\'storage\'](),
null
);
\\Laminas\\Session\\Container::setDefaultManager($sessionManager);
return $sessionManager;
},
],
],
];';
my $regex = qr/'controllers' => \[\s*\K('factories' => )(\[((?>[^][]++|(?2))*)])/mp;
if ( $str =~ /$regex/g ) {
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