protected function getWordsRegexp(array $words) { $expr = RegexpBuilder::fromList($words, $this->regexpOptions); $expr = \preg_replace('/(?<!\\\\)((?>\\\\\\\\)*)\\(\\?:/', '$1(?>', $expr); $regexp = new Regexp('/(?<![\\pL\\pN])' . $expr . '(?![\\pL\\pN])/Siu'); $regexp->setJS('/(?:^|\\W)' . \str_replace('[\\pL\\pN]', '[^\\s!-\\/:-?]', $expr) . '(?!\\w)/gi'); return $regexp; }
/** * Encode a Regexp object into JavaScript * * @param Regexp $regexp * @return string */ protected function encodeRegexp(Regexp $regexp) { return (string) $regexp->toJS(); }
/** * @testdox getCaptureNames() returns the names of all captures */ public function testGetCaptureNames() { $ap = new Regexp('#(?<year>\\d{4}) (?<name>[a-z]+)#'); $this->assertSame(['', 'year', 'name'], $ap->getCaptureNames()); }
protected function encodeRegexp(Regexp $regexp) { return $regexp->getJS(); }