- var_dump: documentation ( source)
- preg_match: documentation ( source)
- preg_replace: documentation ( source)
<?php
$string = '43_this_2 is test';
preg_match('/(?P<test>\w+)/', $string, $matches); // basic syntax
var_dump($matches['test']);
preg_match('/(?<test>.+)/', $string, $matches); // alternative
var_dump($matches['test']);
preg_match("/(?'test'.+)/", $string, $matches); // alternative
var_dump($matches['test']);
echo preg_replace('/\{(\w+)\}/', '(?<\1>\w+)', '/users/{user}/photos/{photo}');