public function testFindAllFrom() { // ASCII. $foundStrings; $numFound = CRegex::findAllFrom("Hello there!", "/\\w+/", 5, $foundStrings); $this->assertTrue($numFound == 1 && CArray::length($foundStrings) == 1 && CString::equals($foundStrings[0], "there")); $foundStrings; $numFound = CRegex::findAllFrom("Hello there!", "/H\\w+/", 5, $foundStrings); $this->assertTrue($numFound == 0); // Unicode. $foundStrings; $numFound = CRegex::findAllFrom("¡Hello señor!", "/\\S+/u", 7, $foundStrings); $this->assertTrue($numFound == 1 && CArray::length($foundStrings) == 1 && CUString::equals($foundStrings[0], "señor!")); $foundStrings; $numFound = CRegex::findAllFrom("¡Hello señor!", "/H\\w+/u", 7, $foundStrings); $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 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. * @param int $startPos The starting position for the search. * @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 reFindAllFrom($findPattern, $startPos, &$foundStrings = null) { $findPattern = self::ensureUModifier($findPattern); $ret = CRegex::findAllFrom($this, $findPattern, $startPos, $foundStrings); $foundStrings = to_oop($foundStrings); return $ret; }