Answer the question
In order to leave comments, you need to log in
How to pass all elements of a subpattern in a regular expression?
Hello, I have a regular expression:
$content = preg_replace_callback('/{([a-z]{1,9})(\s[a-z]{1,9}){0,9}}/', 'function123', $content);
This regular expression should process such strings as {name parameter parameter....} The Answer the question
In order to leave comments, you need to log in
if you need to get ['title' , 'abc' , 'zxc' , 'qwe'] - then you can just
/[az]{1,9}/
I would do something like this:
$content = '{title abc zxc qwe} test {title abc zxc qwe} {title}';
function matches($matches) {
$title = $matches['title'];
$params = isset($matches['params']) ? preg_split('/\s/', $matches['params']) : array();
var_dump($title);
var_dump($params);
}
$content = preg_replace_callback('/\{(?P<title>[a-z]{1,9})(?:\s(?P<params>[^}]+))?\}/', 'matches', $content);
print $content;
something like this
$content = preg_replace_callback('/(?:{)([a-z]{1,9})\s([a-z]{1,9})\s([a-z]{1,9})\s([a-z]{1,9})/', function($a) {
var_dump($a);
}, '{title abc zxc qwe}');
and preg_match_all will not save the situation?
preg_match_all('/[a-z]{1,9}/','{title abc zxc qwe}', $matches);
var_dump($matches);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question