// include the latest version of the regex crate in your Cargo.toml
extern crate regex;
use regex::Regex;
fn main() {
let regex = Regex::new(r"(?m)'controllers' => \[\s*\K('factories' => )(\[((?>[^][]++|(?2))*)])").unwrap();
let string = "<?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;
},
],
],
];";
// result will be an iterator over tuples containing the start and end indices for each match in the string
let result = regex.captures_iter(string);
for mat in result {
println!("{:?}", mat);
}
}
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 Rust, please visit: https://docs.rs/regex/latest/regex/