Perform a pattern assertion.

@param string $value
@param string $pattern
@param string $message
764662
public function match($value, $pattern, $message = '')
    {
        $this->assertion->setActual($value);

        return $this->assertion->to->match($pattern, $message);
    }
353435
public static function match($pattern, $value)
    {
        if ($pattern == $value) {
            return true;
        }

        $pattern = preg_quote($pattern, '#');
        if ($pattern !== '/') {
            $pattern = str_replace('\*', '.*', $pattern) . '\z';
        } else {
            $pattern = '/$';
        }

        return (bool) preg_match('#^' . $pattern . '#', $value);
    }
435561
protected function assertNotRegExp($pattern, $string, $message = '')
    {
        \PHPUnit\Framework\Assert::assertNotRegExp($pattern, $string, $message);
    }
1261588
public function checkLike($value, $pattern, $escape='\\')
    {

        if (!Type::isStringable($value) || !Type::isStringable($pattern)) {
            return false;
        }

        $value = "$value";
        $pattern = "$pattern";

        // @see https://stackoverflow.com/questions/11434305/simulating-like-in-php

        // Split the pattern into special sequences and the rest
        $expr = '/((?:'.preg_quote($escape, '/').')?(?:'.preg_quote($escape, '/').'|%|_))/';
        $parts = preg_split($expr, $pattern, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);

        // Loop the split parts and convert/escape as necessary to build regex
        $expr = '/^';

        $lastWasPercent = false;

        foreach ($parts as $part) {
            switch ($part) {
                case $escape.$escape:
                    $expr .= preg_quote($escape, '/');
                    break;
                case $escape.'%':
                    $expr .= '%';
                    break;
                case $escape.'_':
                    $expr .= '_';
                    break;
                case '%':
                    if (!$lastWasPercent) {
                        $expr .= '.*?';
                    }
                    break;
                case '_':
                    $expr .= '.';
                    break;
                default:
                    $expr .= preg_quote($part, '/');
                    break;
            }

            $lastWasPercent = $part == '%';

        }

        $expr .= '$/i';

        // Look for a match and return bool
        return (bool)preg_match($expr, $value);
    }
1312382
public static function buildPatternLine($pattern, $length)
    {
        $result = '';
        for ($i = 0; $i < $length; $i++) {
            $result .= $pattern;
        }

        return $result;
    }
218685
public static function isCallable($value, $message = null)
    {
        if (!is_callable($value)) {
            throw new InvalidArgumentException(sprintf(
                $message ?: 'Expected callable, but got %s',
                Helper::typeToString($value)
            ));
        }
    }
305299
public function getAll($value, $pattern, $group = 0)
    {
        if (!isset($value)) {
            return null;
        }
        
        return preg_match_all($pattern, $value, $matches, PREG_PATTERN_ORDER) && isset($matches[$group])
            ? $matches[$group] : [];
    }
562256
public function regex($key, $pattern, $message = null)
    {
        if (is_array($key)) {
            foreach ($key as $k => $name) {
                $this->regex($name, is_array($pattern) ? $pattern[$k] : $pattern, $message);
            }
        } else {
            if (isset($this->scope[$key]) && ! (bool)preg_match($pattern, $this->scope[$key])) {
                $this->errors[$key] = sprintf($message !== null ? $message : self::$regexMessage, $key);
            }
        }

        return $this;
    }
418692
protected function _checkPcrePattern($pattern = null) {
		if (empty($pattern)) {
			return null;
		}

		$result = true;
		try {
			//@codingStandardsIgnoreStart
			$matchResult = @preg_match($pattern, 'some text');
			//@codingStandardsIgnoreEnd
			if ($matchResult === false) {
				$result = false;
			}
		} catch (Exception $exception) {
			$result = false;
		}

		return $result;
	}
943140
public function respond(Match $match, TemplateInterface $template, $message = '')
    {
        if ($match->isMatch()) {
            return;
        }

        $this->formatter->setMatch($match);
        $message = ($message) ? $message : $this->formatter->getMessage($template);
        throw new AssertionException($message);
    }
274416
public function filter($value, $pattern, $replacement = '', $limit = -1)
    {
        $this->assertNoEval($pattern);
        
        if (!isset($value)) {
            return null;
        }
        
        return preg_filter($pattern, $replacement, $value, $limit);
    }
75129
public function visitPatternConstraint(StringValue\PatternConstraint $constraint)
    {
        $value = $this->currentValue();
        if (
            !$value instanceof Value\StringValue ||
            preg_match(
                $this->wrapPattern($constraint->pattern()),
                $value->value()
            )
        ) {
            return $this->createResult();
        }

        return $this->createSingleIssueResult($constraint);
    }
433624
private static function isValidRegex($pattern)
    {
        try {
            return preg_match(sprintf('~%s~', $pattern), null) !== false;
        } catch (\Exception $e) {
            return false;
        }
    }
33835
private function matchPattern($pathName, $pattern)
    {
        if ($pattern[0] !== '/') {
            $pattern = '**/' . $pattern;
        }

        if (\fnmatch($pattern, $pathName)) {
            return true;
        }

        return false;
    }
1277652
public function setPattern($pattern)
    {
        if (gettype($pattern) === 'string') {
            $this->pattern = $pattern;
        } else {
            $msg = "The pattern argument must be a string or a variable reference, '" . $pattern . "' given.";
            throw new InvalidArgumentException($msg);
        }
    }
1240998
public function run( $field, $value, $message = null ) {
        $this->field   = $field;
        $this->message = $message;
        $value = preg_replace('/^[\pZ\pC]+|[\pZ\pC]+$/u', '', $value);

        return !empty($value);
    }
996337
private function filter(&$value)
    {
        if (isset($this->patterns[$value])) {
            $value = $this->patterns[$value];
        } else {
            // Test that pattern is a valid REGEXP pattern
            ErrorHandler::start();
            $this->pattern = (string) $value;
            $status        = preg_match($this->pattern, "Test");
            $error         = ErrorHandler::stop();
        
            if (false === $status) {
                throw new Exception\InvalidArgumentException("Internal error parsing the pattern '{$this->value}'", 0, $error);
            }
        }
    }