Set regexp of current route

@param   string $regexp
@return  RouteInterface
975093
public function setRegexp(string $regexp): RouteInterface
    {
        $pattern = ['/</', '/>/'];
        $replace = ['(?P<', '>.+)'];
        $regexp = preg_replace($pattern, $replace, $regexp);
        $this->_regexp = '#^' . $regexp . '$#u';
        return $this;
    }
536313
public static function regexp($val, $regexp, $default = null): bool
    {
        $options = [
            'regexp' => $regexp
        ];

        if ($default !== null) {
            $options['default'] = $default;
        }

        return (bool)\filter_var($val, \FILTER_VALIDATE_REGEXP, ['options' => $options]);
    }
1240935
public function parseRoute($routeSpec)
    {
        $path           = isset($routeSpec['path']) ? $routeSpec['path'] : null;
        $methods        = isset($routeSpec['methods']) ? $routeSpec['methods'] : array();
        $controller     = isset($routeSpec['controller']) ? $routeSpec['controller'] : null;
        $calls          = isset($routeSpec['calls']) ? $routeSpec['calls'] : null;
        $requirements   = isset($routeSpec['requirements']) ? $routeSpec['requirements'] : array();
        $regex          = isset($routeSpec['path']) ? $routeSpec['path'] : null;

        $route = new Route($path, $methods, $controller, $calls, $requirements, $regex);

        return $route;
    }
982313
public function regexps(array $regexpsMap)
    {
        return function(FieldExpression $expr, $compiler) use ($regexpsMap)
        {
            $value = $expr->getValue();

            foreach ($regexpsMap as $regexp => $transformation) {
                if (preg_match($regexp, $value))
                    return $transformation($expr, $compiler);
            }

            throw new UnregisteredTransformationException("There is no transformation matching the value \"$value\"");
        };
    }
363536
protected function _compile_regex($route)
    {
        $pattern = '`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`';

        if ( preg_match_all($pattern, $route, $matches, PREG_SET_ORDER) ) {
            $match_types = array(
                'i'  => '[0-9]++',
                'a'  => '[0-9A-Za-z]++',
                'h'  => '[0-9A-Fa-f]++',
                '*'  => '.+?',
                ''   => '[^/]++'
            );
            foreach ( $matches as $match ) {
                list($block, $pre, $type, $param, $optional) = $match;

                if ( isset($match_types[$type]) ) {
                    $type = $match_types[$type];
                }
                if ( $param ) {
                    $param = "?<{$param}>";
                }
                if ( $optional ) {
                    $optional = '?';
                }

                $replaced = "(?:{$pre}({$param}{$type})){$optional}";
                $route = str_replace($block, $replaced, $route);
            }
        }
        if ( substr($route, strlen($route) - 1) != '/' ) {
            $route .= '/?';
        }
        return "`^{$route}$`";
    }
1336620
public function setRegexp($regexp)
	{
		if (is_string($regexp))
		{
			$regexp = new Regexp($regexp);
		}

		$this->vars['regexp'] = $regexp;
		$this->resetSafeness();
		$this->evaluateSafeness();
	}
676803
public function setRegexp($regexp)
    {
        if (is_string($regexp)) {
            $this->regexp = $regexp;
        } else {
            throw new \InvalidArgumentException(
                "Invalid type '" . gettype($regexp) . "' for argument 'regexp' given. String expected."
            );
        }
    }
184404
public function addPattern(string $name, string $regexp)
    {
        $this->regexp_map = ['/\{(\w+):'.$name.'\}/' => '(?<$1>'.$regexp.')'] + $this->regexp_map;
    }
1192272
public function replaceTokens($regexp, $fn)
	{
		$this->inspector    = null;
		$this->template     = TemplateModifier::replaceTokens($this->template, $regexp, $fn);
		$this->isNormalized = false;
	}
11138
private function constructInternalRegularExpression($path, $routePattern)
    {
        if (empty($routePattern)) return false;

        $fullRoute = $path;

        if (substr($fullRoute, -1) == '/') {
            $fullRoute = substr($fullRoute, 0, -1);
        }

        $fullRoute .= $routePattern;

        $patternSegments = $this->urlSegmentsFromPath($fullRoute);

        $variableNumber = 0;
        $hasOptional = false;
        $lastSegmentRequired = true;

        foreach ($patternSegments as $pattern) {
            $variableNumber++;

            $isOptionalPattern = $this->stringIsWrapped($pattern, '[', ']');
            $isDynamicPattern = $this->stringIsWrapped($pattern, '{', '}');

            if (!$isDynamicPattern) {
                $validatorClass = new \Slab\Router\Validators\Value(); //@todo findClass

                $validatorClass->setChallenge($pattern);

                if ($isOptionalPattern)
                {
                    // Can't have optional value validators
                    //$validatorClass->setOptional(true);
                }
                else
                {
                    $this->requiredSegments++;
                }

                $this->validations[] = $validatorClass;

                continue;
            }

            if (!$isOptionalPattern && $hasOptional)
            {
                throw new \Exception("Route " . $path . " has required fields after optional fields.");
            }

            list($validatorClass, $variableName) = explode(':', $pattern);

            if ($validatorClass[0] != '\\')
            {
                $validatorClass = ucfirst($validatorClass);

                if (strcasecmp($validatorClass, 'String') == 0)
                {
                    $validatorClass = 'Text';
                }

                $validatorClassName = '\Slab\Router\Validators\\' . $validatorClass;
            }
            else
            {
                $validatorClassName = $validatorClass;
            }

            if (!class_exists($validatorClassName))
            {
                throw new \Exception("Route " . $path . " specified invalid validator class " . $validatorClass);
            }


            $validatorClass = new $validatorClassName;

            if (!$validatorClass instanceof \Slab\Router\Validators\ValidatorInterface)
            {
                throw new \Exception("Validator " . $validatorClass . " does not explicitly implement interface \Slab\Router\Validators\ValidatorInterface");
            }

            $this->validations[] = $validatorClass;

            $this->variableMapping[$variableNumber] = $variableName;

            if (!$isOptionalPattern)
            {
                ++$this->requiredSegments;
            }
        }

        return true;
    }
162418
public static function urlMatches($urlRegexp)
    {
        return new static(
            function (WebDriver $driver) use ($urlRegexp) {
                return (bool) preg_match($urlRegexp, $driver->getCurrentURL());
            }
        );
    }
1153046
function (regexp) {
        var res = maybeCallNative(nativeSearch, regexp, this);
        if (res.done) return res.value;

        var rx = anObject(regexp);
        var S = String(this);

        var previousLastIndex = rx.lastIndex;
        if (!sameValue(previousLastIndex, 0)) rx.lastIndex = 0;
        var result = regExpExec(rx, S);
        if (!sameValue(rx.lastIndex, previousLastIndex)) rx.lastIndex = previousLastIndex;
        return result === null ? -1 : result.index;
      }
1141498
public function route(
        string $method,
        string $pattern,
        callable $callback,
        int $priority = 0
    ): RouterInterface {
        //hard requirement
        if (!is_callable($callback)) {
            throw HttpException::forInvalidRouteCallback();
        }

        if (strtoupper($method) === 'ALL') {
            $method = '[a-zA-Z0-9]+';
        }

        //find and organize all the dynamic parameters
        preg_match_all('#(\:[a-zA-Z0-9\-_]+)|(\*\*)|(\*)#s', $pattern, $matches);

        $keys = array();
        if (isset($matches[0]) && is_array($matches[0])) {
            $keys = $matches[0];
        }

        //replace the :variable-_name01
        $regex = preg_replace('#(\:[a-zA-Z0-9\-_]+)#s', '*', $pattern);

        //replace the stars
        //* -> ([^/]+)
        $regex = str_replace('*', '([^/]+)', $regex);
        //** -> ([^/]+)([^/]+) -> (.*)
        $regex = str_replace('([^/]+)([^/]+)', '(.*)', $regex);

        //now form the event pattern
        $event = '#^' . $method . '\s' . $regex . '/*$#is';

        //we need the handler for later
        $handler = $this->getEventHandler();

        $handler->on(
            $event,
            function (
                RequestInterface $request,
                ...$args
            ) use (
                $handler,
                $callback,
                $pattern,
                $keys
            ) {
                $route = $handler->getMeta();
                $variables = array();
                $parameters = array();

                //sanitize the variables
                foreach ($route['variables'] as $i => $variable) {
                    //if it's a * variable
                    if (!isset($keys[$i]) || strpos($keys[$i], '*') === 0) {
                        //it's a variable
                        if (strpos($variable, '/') === false) {
                            $variables[] = $variable;
                            continue;
                        }

                        $variables = array_merge($variables, explode('/', $variable));
                        continue;
                    }

                    //if it's a :parameter
                    if (isset($keys[$i])) {
                        $key = substr($keys[$i], 1);
                        $parameters[$key] = $variable;
                    }
                }

                $request
                    ->setStage($parameters)
                    ->setRoute(array(
                        'event' => $route['event'],
                        'variables' => $variables,
                        'parameters' => $parameters
                    ));

                return call_user_func($callback, $request, ...$args);
            },
            $priority
        );

        return $this;
    }
150905
public static function toJS($regexp, $isGlobal = false)
	{
		$regexpInfo = RegexpParser::parse($regexp);
		$dotAll     = (strpos($regexpInfo['modifiers'], 's') !== false);

		$regexp = '';
		$pos = 0;

		foreach ($regexpInfo['tokens'] as $tok)
		{
			$regexp .= self::convertUnicodeCharacters(
				substr($regexpInfo['regexp'], $pos, $tok['pos'] - $pos),
				false,
				$dotAll
			);

			switch ($tok['type'])
			{
				case 'option':
					if ($tok['options'] !== 'J')
					{
						throw new RuntimeException('Regexp options are not supported');
					}
					break;

				case 'capturingSubpatternStart':
					$regexp .= '(';
					break;

				case 'nonCapturingSubpatternStart':
					if (!empty($tok['options']))
					{
						throw new RuntimeException('Subpattern options are not supported');
					}

					$regexp .= '(?:';
					break;

				case 'capturingSubpatternEnd':
				case 'nonCapturingSubpatternEnd':
					$regexp .= ')' . substr($tok['quantifiers'], 0, 1);
					break;

				case 'characterClass':
					$regexp .= '[';
					$regexp .= self::convertUnicodeCharacters($tok['content'], true, false);
					$regexp .= ']' . substr($tok['quantifiers'], 0, 1);
					break;

				case 'lookaheadAssertionStart':
					$regexp .= '(?=';
					break;

				case 'negativeLookaheadAssertionStart':
					$regexp .= '(?!';
					break;

				case 'lookaheadAssertionEnd':
				case 'negativeLookaheadAssertionEnd':
					$regexp .= ')';
					break;

				default:
					throw new RuntimeException("Unsupported token type '" . $tok['type'] . "'");
			}

			$pos = $tok['pos'] + $tok['len'];
		}

		$regexp .= self::convertUnicodeCharacters(substr($regexpInfo['regexp'], $pos), false, $dotAll);

		if ($regexpInfo['delimiter'] !== '/')
		{
			$regexp = preg_replace('#(?<!\\\\)((?:\\\\\\\\)*+)/#', '$1\\/', $regexp);
		}

		$modifiers = preg_replace('#[^im]#', '', $regexpInfo['modifiers']);
		if ($isGlobal)
		{
			$modifiers .= 'g';
		}

		if ($regexp === '')
		{
			$regexp = '(?:)';
		}

		return '/' . self::escapeLineTerminators($regexp) . '/' . $modifiers;
	}
333121
public function setRegexp($pattern)
    {
        $regexp = new RegularExpression();
        $regexp->setPattern($pattern);
        $this->_regexps[] = $regexp;
    }
1281478
public Constraint regexp(String regexp, String type) {
        RegexpConstraint c = new RegexpConstraint(regexp);
        c.setType(type);
        return c;
    }
895285
private function prepareRegexp($exp)
    {
        // remove surrounding '/' marks so that they don't get escaped in next step
        if ($exp{0} !== '/' || $exp{strlen($exp) - 1} !== '/') {
            $exp = '/' . $exp . '/';
        }

        // if they did not escape / chars; we do that for them
        $exp = preg_replace('/([^\\\])\/([^$])/', '$1\/$2', $exp);

        return $exp;
    }