/** * {@inheritDoc} */ public static function groupRegEx($regex, $name = '') { // grouped ? if ($regex[0] === '(') { $pat = static::toPattern(RegEx::balancedString('(', ')')); if (preg_match($pat, $regex, $m) && $m[0] === $regex && $regex[1] !== '?') { // grouped already, just replace with name if any return $name ? "(?<{$name}>" . substr($regex, 1) : $regex; } } return sprintf('(%s%s)', $name ? "?<{$name}>" : '', $regex); }
/** * Return regex to match xml (p)rocessing (i)nstructions * * Quoted substring and heredoc type of substrings are allowed in PI. Key * is the $option setting. * * @param string $target literal target, like 'php' * @param int $option regex option * @return string * @access public * @static */ public static function xmlProcessing($target = 'php', $option = RegExOption::OPTION_ALLOPTS) { return RegEx::stringWithOpenClose('<?' . $target, '?>', $option); }
/** * Return regex to match comma seperated strings * * comma in quotes are ignored. the unrolling pattern implemented * * @param string $char the seperate char, default ',' * @param int $option regex option * @return string * @access public * @static */ public static function commaField($char = ',', $option = RegExOption::OPTION_DEFAULT) { $quoted = RegEx::quotedString($option); return sprintf('(?<=%s|^)[^%s"\']*(?:%s[^%s"\']*)*(?=%s|\\Z)', $char, $char, $quoted, $char, $char); }