An expectation for checking current page URL matches the given regular expression.

@param string $urlRegexp The regular expression to test against.
@return static Condition returns whether current URL matches the regular expression.
162418
public static function urlMatches($urlRegexp)
    {
        return new static(
            function (WebDriver $driver) use ($urlRegexp) {
                return (bool) preg_match($urlRegexp, $driver->getCurrentURL());
            }
        );
    }
672007
public function iShouldSeeTextInXpath($xpath, $regex)
    {
        $result = $this->getSession()->getPage()->find('xpath', $xpath);

        if (is_null($result)) {
            // We should only have one element
            throw new ExpectationException(
                sprintf(
                    'The xpath %s returned no results on %s',
                    $xpath,
                    $this->getSession()->getCurrentUrl()
                ),
                $this->getSession()->getDriver()
            );
        }

        if (0 === preg_match(ReformatRegex::spaceTabsEqual(sprintf('/%s/', $regex)), trim(strip_tags($result->getHtml())))) {
            // Text not found
            throw new ExpectationException(
                sprintf(
                    'The content %s can not be found on %s in element %s',
                    $xpath,
                    $this->getSession()->getCurrentUrl(),
                    $regex
                ),
                $this->getSession()->getDriver()
            );
        }
    }
674214
public static function is($url, $regexp = false) {
        $r = self::getRouter();
        if ($regexp) {
            return preg_match('`^' . $url . '$`', $r->requestURL);
        }

        return $url == $r->requestURL;
    }
505151
function (regexp) {
        var res = maybeCallNative(nativeMatch, regexp, this);
        if (res.done) return res.value;

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

        if (!rx.global) return regExpExec(rx, S);

        var fullUnicode = rx.unicode;
        rx.lastIndex = 0;
        var A = [];
        var n = 0;
        var result;
        while ((result = regExpExec(rx, S)) !== null) {
          var matchStr = String(result[0]);
          A[n] = matchStr;
          if (matchStr === '') rx.lastIndex = advanceStringIndex(S, toLength(rx.lastIndex), fullUnicode);
          n++;
        }
        return n === 0 ? null : A;
      }
53058
public function check($regexp)
    {
        if (preg_match($regexp, $this->getRemainder(), $matches)) {
            if (strlen($matches[0]) &&
                mb_strpos($this->getRemainder(), $matches[0]) === 0) {
                return $this->setState($matches);
            }
        }
        return $this->setState();
    }
927670
public function validateRegexp()
    {
        $val = $this->val();

        $regexp = $this->regexp();
        if ($regexp == '') {
            return true;
        }

        $valid = !!preg_match($regexp, $val);
        if (!$valid) {
            $this->validator()->error('Regexp error', 'regexp');
        }

        return $valid;
    }
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;
      }
125357
public function contains($pattern, $regexp = FALSE)
  {
    if(empty($pattern))
    {
      return TRUE;
    }

    if($regexp)
    {
      return (preg_match("/" . $pattern . "/i", $this->string)) ? TRUE : FALSE;
    }
    else
    {
      return (stristr($this->string, $pattern) !== FALSE) ? TRUE : FALSE;
    }
  }
1029232
protected function matchRegExp($regexp, $string, array &$params)
    {
        if (preg_match($regexp, $string, $params)) {
            $matched = strlen($params[0]);
            $this->filterMatchedParams($params);

            return $matched;
        } else {
            return false;
        }
    }
972053
public function setRegexp($name, $regexp = null)
    {
        if (is_array($name)) {
            $this->regexps = array_merge($this->regexps, $name);
        } else {
            $this->regexps[$name] = $regexp;
        }
        return $this;
    }
975093
public function setRegexp(string $regexp): RouteInterface
    {
        $pattern = ['/</', '/>/'];
        $replace = ['(?P<', '>.+)'];
        $regexp = preg_replace($pattern, $replace, $regexp);
        $this->_regexp = '#^' . $regexp . '$#u';
        return $this;
    }
829117
private function match($exp, $pattern, $value) {
		$pattern = strtolower($pattern);
		$value = strtolower($value);
		switch ($exp) {
			case '=' :
				return ($value === $pattern);
			case '!=' :
				return ($value !== $pattern);
			case '^=' :
				return preg_match("/^" . preg_quote($pattern, '/') . "/", $value);
			case '$=' :
				return preg_match("/" . preg_quote($pattern, '/') . "$/", $value);
			case '*=' :
				if ($pattern [0] == '/') {
					return preg_match($pattern, $value);
				}
				return preg_match("/" . $pattern . "/i", $value);
		}
		return FALSE;
	}
1101526
def valid_url(x: str) -> bool:
    
    if isinstance(x, str) and re.match(URL_PATTERN, x):
        return True
    else:
        return False
651452
public function matchPath($regexp)
	{
		if (substr($regexp, 0, 1) == '@') {
			$this->route_name = substr($regexp, 1);
		} else {
			parent::matchPath($regexp);
		}
	}
336913
public function match(string $uri): bool
    {
        if ($this->uri == $uri) {
            return true;
        }
        $pattern = '/^' . $this->regex . '$/';
        return !is_null($this->regex) && preg_match($pattern, $uri);
    }
1018422
static function matchRegexp( &$text, $reg, $num )
    {
        $reg = str_replace( '/', "\\/", $reg );
        if ( preg_match( "/$reg/", $text, $regs ) && $num < count( $regs ) )
        {
            $text = str_replace( $regs[$num], '', $text );
            return $regs[$num];
        }
        return null;
    }
736169
public function match(UrlObject $url)
    {
        $pathWithHost = $this->str($url->getHost() . $url->getPath())->trimRight('/')->val();
        $pathWithoutHost = $this->str($url->getPath())->trimRight('/')->val();

        /**
         * @var Route $route
         */
        foreach (Router::getRouteCollection()->all() as $name => $route) {
            $compiledRoute = $route->compile();

            // 1. Make sure staticPrefix and path both contain leading slash
            $staticPrefix = $compiledRoute->getStaticPrefix();
            $staticPrefix = $staticPrefix != '' && !$this->str($staticPrefix)->startsWith('/'
            ) ? '/' . $staticPrefix : $staticPrefix;
            $urlPath = $this->str($url->getPath())->startsWith('/') ? $url->getPath() : '/' . $url->getPath();

            // 2. First check the static prefix on path because we don't want to use heavy preg_matching if the prefix doesn't match
            if ($staticPrefix != '' && strpos($urlPath, $staticPrefix) !== 0) {
                continue;
            }

            // let's check the host
            if ($route->getHost() != '' && $route->getHost() != $url->getHost()) {
                continue;
            }

            // let's check schemes
            if (count($route->getSchemes()) > 0 && !in_array($url->getScheme(), $route->getSchemes())) {
                continue;
            }

            // let's check them methods
            if (count($route->getMethods()) > 0 && !in_array($this->request()->server()->requestMethod(),
                                                             $route->getMethods()
                )
            ) {
                continue;
            }

            // check if we need to match the host also
            if ($route->getHost() != '') {
                $fullPath = $pathWithHost;
            } else {
                $fullPath = $pathWithoutHost;
            }

            // 3. Check the root path
            if ($route->getPath() == '' && ($url->getPath() != '/' && $url->getPath() != '')) {
                continue;
            }

            if (!$compiledRoute->getRegex()) {
                if ($fullPath != '') {
                    continue;
                }

                // if there is no regex, that means we can only match an empty path
                $params = [];
            } else {
                // finally let's try to match the full url
                preg_match_all($compiledRoute->getRegex(), $fullPath, $matches);

                if (count($matches[0]) < 1) {

                    // if we haven't matched the url, lets see if we have all the default values for every pattern,
                    // because if we do, and since the static prefix has been matched, we can still consider the url to be
                    // matched
                    if ($compiledRoute->getDefaultRoute()) {
                        preg_match_all($compiledRoute->getRegex(), $compiledRoute->getDefaultRoute(), $matches);
                        if (count($matches[0]) < 1) {
                            continue;
                        }
                    } else {
                        continue;
                    }
                }

                // if we matched the route, we need to extract the parameters
                $params = $this->extractParameters($matches, $compiledRoute);
            }

            return new MatchedRoute($route, $params);
        }

        return false;
    }