Пример #1
0
 public function testFindGroupsFrom()
 {
     // ASCII.
     $foundGroups;
     $found = CRegex::findGroupsFrom("Hello there you!", "/(\\w+) (\\w+)/", 5, $foundGroups);
     $this->assertTrue($found && CArray::length($foundGroups) == 2 && CString::equals($foundGroups[0], "there") && CString::equals($foundGroups[1], "you"));
     $foundGroups;
     $foundString;
     $found = CRegex::findGroupsFrom("Hello there you!", "/(\\w+) (\\S+)/", 5, $foundGroups, $foundString);
     $this->assertTrue($found && CArray::length($foundGroups) == 2 && CString::equals($foundGroups[0], "there") && CString::equals($foundGroups[1], "you!") && CString::equals($foundString, "there you!"));
     $foundGroups;
     $this->assertFalse(CRegex::findGroupsFrom("Hello there!", "/\\b(\\w+) (\\w+)/", 1, $foundGroups));
     // Unicode.
     $foundGroups;
     $found = CRegex::findGroupsFrom("¡Hello señor you!", "/(\\w+) (\\w+)/u", 7, $foundGroups);
     $this->assertTrue($found && CArray::length($foundGroups) == 2 && CUString::equals($foundGroups[0], "señor") && CUString::equals($foundGroups[1], "you"));
     $foundGroups;
     $foundString;
     $found = CRegex::findGroupsFrom("¡Hello señor you!", "/(\\w+) (\\S+)/u", 7, $foundGroups, $foundString);
     $this->assertTrue($found && CArray::length($foundGroups) == 2 && CUString::equals($foundGroups[0], "señor") && CUString::equals($foundGroups[1], "you!") && CUString::equals($foundString, "señor you!"));
     $foundGroups;
     $this->assertFalse(CRegex::findGroupsFrom("¡Hello señor!", "/(\\w+) (\\w+)/u", 7, $foundGroups));
 }
Пример #2
0
 /**
  * Determines if a string contains a specified regular expression pattern, starting the search from a specified
  * position and putting every substring that matches a regular expression group into an array for output,
  * optionally reporting the substring 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 $foundGroups **OUTPUT.** If the pattern was found, this is an array of type `CArrayObject`
  * containing the substrings that matched the groups in the pattern, in the same order, if any.
  * @param  reference $foundString **OPTIONAL. OUTPUT.** If the pattern has been found after the method was called
  * with this parameter provided, the parameter's value, which is of type `CUStringObject`, is the first substring
  * that matched the pattern.
  *
  * @return bool `true` if the pattern was found in the string, `false` otherwise.
  */
 public function reFindGroupsFrom($findPattern, $startPos, &$foundGroups, &$foundString = null)
 {
     $findPattern = self::ensureUModifier($findPattern);
     $ret = CRegex::findGroupsFrom($this, $findPattern, $startPos, $foundGroups, $foundString);
     $foundGroups = to_oop($foundGroups);
     $foundString = to_oop($foundString);
     return $ret;
 }