public function testFindFrom() { // ASCII. $this->assertTrue(CRegex::findFrom("Hello! there!", "/[^\\w ]/", 6)); $foundString; $found = CRegex::findFrom("Hello? there!", "/[^\\w ]/", 6, $foundString); $this->assertTrue($found && CString::equals($foundString, "!")); $this->assertFalse(CRegex::findFrom("Hello! there", "/!/", 6)); // Unicode. $this->assertTrue(CRegex::findFrom("¡Hello there!", "/[^\\p{L} ]/u", 2)); $foundString; $found = CRegex::findFrom("¡Hello? There!", "/[^\\p{L} ]/u", 8, $foundString); $this->assertTrue($found && CUString::equals($foundString, "!")); $this->assertFalse(CRegex::findFrom("¡Hello 2 you there!", "/\\d/u", 9)); }
/** * Determines if a string contains a specified regular expression pattern, starting the search from a specified * position and 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. * @param int $startPos The starting position for the search. * @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 reFindFrom($findPattern, $startPos, &$foundString = null) { $findPattern = self::ensureUModifier($findPattern); $ret = CRegex::findFrom($this, $findPattern, $startPos, $foundString); $foundString = to_oop($foundString); return $ret; }