/** * does an input regex state match a target states' name? * * @param State $regex * the regex state * @param State $target * the state to match the regular expression to * @return boolean * @link https://php.net/manual/en/function.preg-match.php * @link http://regexr.com/ for trying out regular expressions */ public static function matchesRegex(State $regex, State $target) { $matches = false; if ($regex->isNormalRegex()) { $expression = str_replace(State::REGEX_PREFIX, '', $regex->getName()); $matches = preg_match($expression, $target->getName()) === 1; } if ($regex->isNegatedRegex()) { $expression = str_replace(State::REGEX_PREFIX_NEGATED, '', $regex->getName()); $matches = preg_match($expression, $target->getName()) !== 1; } return $matches; }
/** * @test * @group regex */ public function shouldNotReturnRegexState() { $name = 'rege:.*'; $regex = new State($name); $this->assertFalse($regex->isRegex()); $this->assertFalse($regex->isNormalRegex()); $this->assertFalse($regex->isNegatedRegex()); }