public function testFindAll() { // ASCII. $numFound = CRegex::findAll("Hello there!", "/\\w+/"); $this->assertTrue($numFound == 2); $foundStrings; $numFound = CRegex::findAll("Hello there!", "/\\w+/", $foundStrings); $this->assertTrue($numFound == 2 && CArray::length($foundStrings) == 2 && CString::equals($foundStrings[0], "Hello") && CString::equals($foundStrings[1], "there")); $foundStrings; $numFound = CRegex::findAll("Hello there!", "/a\\w+/", $foundStrings); $this->assertTrue($numFound == 0); // Unicode. $numFound = CRegex::findAll("¡Hello señor!", "/\\w+/u"); $this->assertTrue($numFound == 2); $foundStrings; $numFound = CRegex::findAll("¡Hello señor!", "/\\w+/u", $foundStrings); $this->assertTrue($numFound == 2 && CArray::length($foundStrings) == 2 && CUString::equals($foundStrings[0], "Hello") && CUString::equals($foundStrings[1], "señor")); $foundStrings; $numFound = CRegex::findAll("¡Hello señor!", "/a\\w+/u", $foundStrings); $this->assertTrue($numFound == 0); }
/** * Tells how many matches of a specified regular expression pattern there are in a string, optionally reporting the * substrings that matched the pattern. * * @param string $findPattern The searched pattern. * @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 reFindAll($findPattern, &$foundStrings = null) { $findPattern = self::ensureUModifier($findPattern); $ret = CRegex::findAll($this, $findPattern, $foundStrings); $foundStrings = to_oop($foundStrings); return $ret; }