I am interested in determining whether named groups were used in the template passed to preg_match ().
Imagine a scenario in which the list of regular expression patterns is repeated and passed to preg_match (). Something like the following:
$trg = "123abc/4";
$patterns = array('/abc/', '/abc\/(\d+)/', '/abc\/(?P<id>\d+)/');
foreach ($patterns as $p) {
preg_match($p, $trg, $matches);
if (len($matches) > 0) {
}
}
If a match is found, then there will be at least one element in $ match. The last two templates contain a capture, but $ match will be an array of two elements in the first case and an array of three elements in the last.
I want to know without a grepping pattern if named groups have been used. I need to know this because I want to pass the captured text to other functions.
, , .
, ?
.