Ejemplo n.º 1
0
 public function testFindAllGroups()
 {
     // ASCII.
     $foundGroupArrays;
     $numFound = CRegex::findAllGroups("Hello there!", "/(\\w\\w)(\\w\\w)/", $foundGroupArrays);
     $this->assertTrue($numFound == 2 && CArray::length($foundGroupArrays) == 2 && CString::equals($foundGroupArrays[0][0], "He") && CString::equals($foundGroupArrays[0][1], "ll") && CString::equals($foundGroupArrays[1][0], "th") && CString::equals($foundGroupArrays[1][1], "er"));
     $foundGroupArrays;
     $foundStrings;
     $numFound = CRegex::findAllGroups("Hello there!", "/(\\w\\w)(\\w\\w)/", $foundGroupArrays, $foundStrings);
     $this->assertTrue($numFound == 2 && CArray::length($foundGroupArrays) == 2 && CString::equals($foundGroupArrays[0][0], "He") && CString::equals($foundGroupArrays[0][1], "ll") && CString::equals($foundGroupArrays[1][0], "th") && CString::equals($foundGroupArrays[1][1], "er") && CArray::length($foundStrings) == 2 && CString::equals($foundStrings[0], "Hell") && CString::equals($foundStrings[1], "ther"));
     $foundGroupArrays;
     $numFound = CRegex::findAllGroups("Hello there!", "/(\\w\\w\\w)(\\w\\w\\w)/", $foundGroupArrays);
     $this->assertTrue($numFound == 0);
     // Unicode.
     $foundGroupArrays;
     $numFound = CRegex::findAllGroups("¡Hello señor!", "/(\\w\\w)(\\w\\w)/u", $foundGroupArrays);
     $this->assertTrue($numFound == 2 && CArray::length($foundGroupArrays) == 2 && CUString::equals($foundGroupArrays[0][0], "He") && CUString::equals($foundGroupArrays[0][1], "ll") && CUString::equals($foundGroupArrays[1][0], "se") && CUString::equals($foundGroupArrays[1][1], "ño"));
     $foundGroupArrays;
     $foundStrings;
     $numFound = CRegex::findAllGroups("¡Hello señor!", "/(\\w\\w)(\\w\\w)/u", $foundGroupArrays, $foundStrings);
     $this->assertTrue($numFound == 2 && CArray::length($foundGroupArrays) == 2 && CUString::equals($foundGroupArrays[0][0], "He") && CUString::equals($foundGroupArrays[0][1], "ll") && CUString::equals($foundGroupArrays[1][0], "se") && CUString::equals($foundGroupArrays[1][1], "ño") && CArray::length($foundStrings) == 2 && CUString::equals($foundStrings[0], "Hell") && CUString::equals($foundStrings[1], "seño"));
     $foundGroupArrays;
     $numFound = CRegex::findAllGroups("¡Hello señor!", "/(\\w\\w\\w)(\\w\\w\\w)/u", $foundGroupArrays);
     $this->assertTrue($numFound == 0);
 }
Ejemplo n.º 2
0
 /**
  * Tells how many matches of a specified regular expression pattern there are in a string, 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 and optionally reporting the substrings that matched the pattern.
  *
  * @param  string $findPattern The searched pattern, usually with groups.
  * @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 reFindAllGroups($findPattern, &$foundGroupArrays, &$foundStrings = null)
 {
     $findPattern = self::ensureUModifier($findPattern);
     $ret = CRegex::findAllGroups($this, $findPattern, $foundGroupArrays, $foundStrings);
     $foundGroupArrays = to_oop($foundGroupArrays);
     $foundStrings = to_oop($foundStrings);
     return $ret;
 }