public function testFindAllGroupsFrom() { // ASCII. $foundGroupArrays; $numFound = CRegex::findAllGroupsFrom("Hello there!", "/(\\w\\w)(\\w\\w)/", 1, $foundGroupArrays); $this->assertTrue($numFound == 2 && CArray::length($foundGroupArrays) == 2 && CString::equals($foundGroupArrays[0][0], "el") && CString::equals($foundGroupArrays[0][1], "lo") && CString::equals($foundGroupArrays[1][0], "th") && CString::equals($foundGroupArrays[1][1], "er")); $foundGroupArrays; $foundStrings; $numFound = CRegex::findAllGroupsFrom("Hello there!", "/(\\w\\w)(\\w\\w)/", 1, $foundGroupArrays, $foundStrings); $this->assertTrue($numFound == 2 && CArray::length($foundGroupArrays) == 2 && CString::equals($foundGroupArrays[0][0], "el") && CString::equals($foundGroupArrays[0][1], "lo") && CString::equals($foundGroupArrays[1][0], "th") && CString::equals($foundGroupArrays[1][1], "er") && CArray::length($foundStrings) == 2 && CString::equals($foundStrings[0], "ello") && CString::equals($foundStrings[1], "ther")); $foundGroupArrays; $numFound = CRegex::findAllGroupsFrom("Hello there!", "/(\\w\\w\\w)(\\w\\w\\w)/", 1, $foundGroupArrays); $this->assertTrue($numFound == 0); // Unicode. $foundGroupArrays; $numFound = CRegex::findAllGroupsFrom("¡Hello señor!", "/(\\w\\w)(\\w\\w)/u", 3, $foundGroupArrays); $this->assertTrue($numFound == 2 && CArray::length($foundGroupArrays) == 2 && CUString::equals($foundGroupArrays[0][0], "el") && CUString::equals($foundGroupArrays[0][1], "lo") && CUString::equals($foundGroupArrays[1][0], "se") && CUString::equals($foundGroupArrays[1][1], "ño")); $foundGroupArrays; $foundStrings; $numFound = CRegex::findAllGroupsFrom("¡Hello señor!", "/(\\w\\w)(\\w\\w)/u", 3, $foundGroupArrays, $foundStrings); $this->assertTrue($numFound == 2 && CArray::length($foundGroupArrays) == 2 && CUString::equals($foundGroupArrays[0][0], "el") && CUString::equals($foundGroupArrays[0][1], "lo") && CUString::equals($foundGroupArrays[1][0], "se") && CUString::equals($foundGroupArrays[1][1], "ño") && CArray::length($foundStrings) == 2 && CUString::equals($foundStrings[0], "ello") && CUString::equals($foundStrings[1], "seño")); $foundGroupArrays; $numFound = CRegex::findAllGroupsFrom("¡Hello señor!", "/(\\w\\w\\w)(\\w\\w\\w)/u", 3, $foundGroupArrays); $this->assertTrue($numFound == 0); }
/** * Tells how many matches of a specified regular expression pattern there are in a string, starting the search from * a specified position and putting every substring that matches a regular expression group into an array for * output so that each match of the pattern is associated with an array of group matches, optionally reporting the * substrings that matched the pattern. * * **NOTE.** Unlike the non-regex methods of the class, which count positions within a Unicode string in * characters, the PCRE engine and therefore this method count positions in bytes. * * @param string $findPattern The searched pattern, usually with groups. * @param int $startPos The starting position for the search. * @param reference $foundGroupArrays **OUTPUT.** If any patterns were found, this is a two-dimensional array of * type `CArrayObject`, per each pattern match containing an array of the substrings that matched the groups in the * pattern, in the same order, if any. * @param reference $foundStrings **OPTIONAL. OUTPUT.** If any patterns have been found after the method was * called with this parameter provided, the parameter's value is an array of type `CArrayObject` containing the * substrings that matched the pattern, in the order of appearance. * * @return int The number of matches of the pattern in the string. */ public function reFindAllGroupsFrom($findPattern, $startPos, &$foundGroupArrays, &$foundStrings = null) { $findPattern = self::ensureUModifier($findPattern); $ret = CRegex::findAllGroupsFrom($this, $findPattern, $startPos, $foundGroupArrays, $foundStrings); $foundGroupArrays = to_oop($foundGroupArrays); $foundStrings = to_oop($foundStrings); return $ret; }