hunzhiwange/framework · Dispatch.php
php logo
protected function prepareRegexForWildcard(string $regex): string
    {
        $regex = preg_quote($regex, '/');
        $regex = '/^'.str_replace('\*', '(\S*)', $regex).'$/';

        return $regex;
    }
Similar code snippets
1.
hunzhiwange/framework · Validator.php
Match rating: 82.65% · See similar code snippets
php logo
protected function prepareRegexForWildcard(string $regex, bool $strict = true): string
    {
        $regex = preg_quote($regex, '/');
        $regex = '/^'.str_replace('\*', '(\S+)', $regex).($strict ? '$' : '').'/';

        return $regex;
    }
2.
Match rating: 76.65% · See similar code snippets
php logo
private function _getLikeRegex($string)
  {
    $regex = preg_quote($string, '/');
    $regex = preg_replace('/(?<!\\\\)%/', '.*?', $regex);
    $regex = str_replace('\\\\%', '\\%', $regex);
    return '/^' . $regex . '$/';
  }
3.
samurai-fw/samurai · GlobExpression.php
Match rating: 74.39% · See similar code snippets
php logo
public function getRegexPattern()
    {
        $regex = preg_quote($this->value, '/');
        $regex = substr($regex, -1) !== '*' ? $regex . '$' : $regex;
        $regex = preg_replace('/\\\\\\*/', '.*?', $regex);
        return "/^{$regex}/";
    }
4.
greg-md/php-router · RouteUtils.php
Match rating: 71.44% · See similar code snippets
php logo
private static function paramFetchRegex(string $regex): string
    {
        if ($regex === '*') {
            return '.+?';
        }

        $regex = Regex::disableGroups($regex);

        if ($regex[-1] == '+' or $regex[-1] == '*') {
            $regex .= '?';
        }

        return $regex;
    }
5.
ncou/Chiron · Route.php
Match rating: 68.72% · See similar code snippets
php logo
private function sanitizeRequirement(string $key, string $regex): string
    {
        if ('' !== $regex && '^' === $regex[0]) {
            $regex = substr($regex, 1); // returns false for a single character
        }
        if ('$' === substr($regex, -1)) {
            $regex = substr($regex, 0, -1);
        }
        if ('' === $regex) {
            throw new InvalidArgumentException(sprintf('Routing requirement for "%s" cannot be empty.', $key));
        }

        return $regex;
    }
6.
fortrabbit/datafilter · Basic.php
Match rating: 68.52% · See similar code snippets
php logo
public static function ruleRegex($regex)
    {
        $args = func_get_args();
        $regex = join(':', $args);

        /*not in format "/../<modifier>", "#..#<modifier>"  nor "~..~<modifier>" */
        if (!preg_match('/^([\/#~]).+\1[msugex]*$/', $regex)) {
            $regex = '/'. stripslashes($regex). '/';
        }

        return function ($input) use ($regex) {
            return preg_match($regex, $input);
        };
    }
7.
InterNations/http-mock · RegexMatcher.php
Match rating: 68.28% · See similar code snippets
php logo
protected function createMatcher()
    {
        $regex = $this->regex;

        return static function ($value) use ($regex) {
            return (bool) preg_match($regex, $value);
        };
    }
8.
rollerworks/app-sectioning · SectionConfiguration.php
Match rating: 67.58% · See similar code snippets
php logo
private static function stripDelimiters(?string $regex): ?string
    {
        if (null === $regex || mb_strlen($regex) < 2) {
            return $regex;
        }

        return mb_substr($regex, 1, mb_strrpos($regex, $regex[0], 0, 'UTF-8') - 1, 'UTF-8');
    }
9.
wikimedia/remex-html · GenerateDataFiles.php
Match rating: 67.48% · See similar code snippets
php logo
private function makeRegexAlternation( $array ) {
		$regex = '';
		foreach ( $array as $value ) {
			if ( $regex !== '' ) {
				$regex .= '|';
			}
			$regex .= "\n\t\t" . preg_quote( substr( $value, 1 ), '~' );
		}
		return $regex;
	}
10.
ventoviro/windwalker · BasicCompiler.php
Match rating: 67.31% · See similar code snippets
php logo
protected static function replaceWildcards($regex)
    {
        preg_match_all(chr(1) . '\(\\*([a-z][a-zA-Z0-9]*)\)' . chr(1), $regex, $matches, PREG_SET_ORDER);

        foreach ($matches as $match) {
            $name = $match[1];

            $regex = str_replace("(*{$name})", "(?P<{$name}>.*)", $regex);
        }

        return $regex;
    }