Matches a regular expression

@param string $pattern
The regular expression to execute
@param string $subject
The string to search within
@return boolean
500405
public function match($pattern, $subject)
    {
        if (! $this->validate($pattern)) {
            return false;
        }
        
        return $this->getInstance()->match($pattern, $subject);
    }
280636
public static function replace(string $subject, $pattern, $replacement = null, int $limit = -1): string
    {
        if (\is_object($replacement) || \is_array($replacement)) {
            if (!\is_callable($replacement, false, $textual)) {
                throw new RegexpException("Callback '$textual' is not callable.");
            }

            return static::pcre('preg_replace_callback', [$pattern, $replacement, $subject, $limit]);

        }

        if ($replacement === null && \is_array($pattern)) {
            $replacement = \array_values($pattern);
            $pattern = \array_keys($pattern);
        }

        return static::pcre('\preg_replace', [$pattern, $replacement, $subject, $limit]);
    }
423013
public function match($regexp, $flag = PREG_PATTERN_ORDER, $offset = 0)
    {
        if ((bool) preg_match_all($regexp, $this->subject, $matches, $flag, $offset) === false) {
            return;
        }

        return $matches;
    }
333463
public static function strIs($patterns, $subject, &$matchedPattern = '', $caseSensitive = false)
    {
        if (!is_array($patterns)) {
            $patterns = (array) $patterns;
        }

        $lowerSubject = strtolower($subject);

        foreach ($patterns as $pattern) {

            if ($caseSensitive) {
                if (str_is($pattern, $subject)) {
                    $matchedPattern = $pattern;
                    return true;
                }
            } else {
                $lowerPattern = strtolower($pattern);
                if (str_is($lowerPattern, $lowerSubject)) {
                    $matchedPattern = $pattern;
                    return true;
                }
            }

        }

        return false;
    }
751123
public static function isMatch($value, string $pattern): bool
    {
        if (!static::isStringCastable($value)) {
            return false;
        }

        return !!preg_match($pattern, (string) $value);
    }
789104
private static function matchesAny(array $regexes, $subject)
    {
        $matches = null;
        foreach ($regexes as $regex) {
            if ( ! in_array(preg_match("/$regex/", $subject, $matches), [0, false])) {
                return $matches;
            }
        }
    }
1315437
public function validate($subject): bool
    {
        $pattern = '/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(\.\d{2})?(Z|([+-](\d{2}):(\d{2})))$/';
        if (!\preg_match($pattern, $subject, $matches)) {
            return false;
        }

        $dateYear = \intval($matches[1]);
        $dateMonth = \intval($matches[2]);
        $dateDay = \intval($matches[3]);
        $timeHour = \intval($matches[4]);
        $timeMinutes = \intval($matches[5]);
        $timeSeconds = \intval($matches[6]);
        $tzTime = null;
        $tzTimeHours = 0;
        $tzTimeMinutes = 0;

        if (isset($matches[9])) {
            $tzTime = $matches[9];
        }
        if (isset($matches[10])) {
            $tzTimeHours = \intval($matches[10]);
        }
        if (isset($matches[11])) {
            $tzTimeMinutes =  \intval($matches[11]);
        }

        if (!$this->validateDate($dateYear, $dateMonth, $dateDay)) {
            return false;
        }
        if (!$this->validateTime($timeHour, $timeMinutes, $timeSeconds)) {
            return false;
        }
        if ($tzTime !== null && !$this->validateTimezoneTime($tzTimeHours, $tzTimeMinutes)) {
            return false;
        }
        return true;
    }
586997
public static int preg_match(String regex, String subject) {
        Pattern p = Pattern.compile(regex);
        return preg_match(p, subject);
    }
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;
	}
427428
public function alphaNum($subject, string $case = '') : bool
    {
        if ($subject === null) {
            return false;
        }
        $v = '' . $subject;
        if ($v === '') {
            return false;
        }
        switch ($case) {
            case 'lower':
                $regex = '/^[a-z\d]+$/';
                break;
            case 'upper':
                $regex = '/^[A-Z\d]+$/';
                break;
            default:
                $regex = '/^[a-zA-Z\d]+$/';
                break;
        }
        // ctype_... is no good for ASCII-only check, if PHP and server locale
        // is set to something non-English.
        return !!preg_match($regex, $v);
    }
91625
function match($subject, &$match) {
            if (count($this->_patterns) == 0) {
                return false;
            }
            if (!preg_match($this->_getCompoundedRegex(), $subject, $matches)) {
                $match = "";
                return false;
            }
            $match = $matches[0];
            for ($i = 1; $i < count($matches); $i++) {
                if ($matches[$i]) {
                    return $this->_labels[$i - 1];
                }
            }
            return true;
        }
1346572
protected function matchEventName(string $pattern, Event $event) : bool
    {
        $subject = $event->getName();

        // if event name include pattern, consider to be matched
        if (strpos($subject, $pattern) !== false){
            return true;
        }

        // if event name matches as regex, consider to be matched
        $regex = preg_quote($pattern, '/');
        if (@preg_match("/$regex/", $subject, $match)){
            return true;
        }

        return false;
    }
204433
private function isValidPattern(string $pattern): bool
    {
        set_error_handler(function (int $severity, string $message, string $file, int $line): bool {
            throw new \ErrorException($message, 0, $severity, $file, $line);
        }, \E_ALL);

        try {
            $result = preg_match("/$pattern/", '');
        } catch (\ErrorException $exception) {
            $errorMessage = sprintf("Invalid regular expression '%s': %s", $pattern, $exception->getMessage());
            throw new \InvalidArgumentException($errorMessage, 0, $exception);
        } finally {
            restore_error_handler();
        }

        return $result !== false;
    }
433624
private static function isValidRegex($pattern)
    {
        try {
            return preg_match(sprintf('~%s~', $pattern), null) !== false;
        } catch (\Exception $e) {
            return false;
        }
    }
36679
protected function validatePattern($pattern)
    {
        if (!preg_match('/(?<modifier>[imsxeADSUXJu]+)$/', $pattern, $matches)) {
            return true;
        }

        if (false !== strstr($matches['modifier'], 'e')) {
            throw new Exception\InvalidArgumentException(sprintf(
                'Pattern for a PregReplace filter may not contain the "e" pattern modifier; received "%s"',
                $pattern
            ));
        }
    }
856649
public function plainText($subject) : bool
    {
        if ($subject === null) {
            return false;
        }
        $v = '' . $subject;
        return $v === '' ? true : !strcmp($v, strip_tags($v));
    }
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;
	}