protected function RegexCounter::findHellternations in Bibliography Module 7.2
Returns the hellternations which are siblings to each other. NOTE: the given $pattern is assumed to not contain escaped parentheses.
Parameters
string $pattern a string of alternations wrapped into (?|...):
Return value
array
Throws
1 call to RegexCounter::findHellternations()
- RegexCounter::countGroups in lib/
msrc-authortool/ src/ Nametools/ RegexCounter.php - Returns how many groups (numbered or named) there are in the given $pattern
File
- lib/
msrc-authortool/ src/ Nametools/ RegexCounter.php, line 126
Class
- RegexCounter
- Regexcounter is a class that counts the expected number of matches for a given REGEX pattern
Namespace
NametoolsCode
protected function findHellternations($pattern) {
$result = array();
$token = '(?|';
$tokenLen = strlen($token);
$offset = 0;
do {
$start = strpos($pattern, $token, $offset);
if (FALSE === $start) {
return $result;
}
$open = 1;
$start += $tokenLen;
for ($i = $start, $iTop = strlen($pattern); $i < $iTop; $i++) {
//$current = $pattern[$i];
if ($pattern[$i] == '(') {
$open += 1;
}
elseif ($pattern[$i] == ')') {
$open -= 1;
if (0 == $open) {
$result[$start] = substr($pattern, $start, $i - $start);
$offset = $i + 1;
break;
}
}
}
} while ($i < $iTop);
if (0 != $open) {
throw new RegexCounterException('Unbalanced parentheses.');
}
return $result;
}