Supported Versions: PHP 4, PHP 5, PHP 7, PHP 8
Perform a regular expression match
<?php preg_match(    string $pattern,    string $subject,    array &$matches = null,    int $flags = 0,    int $offset = 0): int|false
<?php         }



        return $request->route($model, null) ??

            ((preg_match("/^['\"](.*)['\"]$/", trim($model), $matches)) ? $matches[1] : null);

    }
<?php     protected function extractChannelKeys($pattern, $channel)

    {

        preg_match('/^'.preg_replace('/\{(.*?)\}/', '(?<$1>[^\.]+)', $pattern).'/', $channel, $keys);



        return $keys;

    }
<?php     protected function channelNameMatchesPattern($channel, $pattern)

    {

        return preg_match('/^'.preg_replace('/\{(.*?)\}/', '([^\.]+)', $pattern).'$/', $channel);

    }
<?php         }



        foreach ($this->files->files($storagePath) as $file) {

            if (preg_match('/facade-.*\.php$/', $file)) {

                $this->files->delete($file);

            }

        }
<?php     protected function sortImports($stub)

    {

        if (preg_match('/(?P<imports>(?:^use [^;{]+;$\n?)+)/m', $stub, $match)) {

            $imports = explode("\n", trim($match['imports']));



            sort($imports);
<?php     protected static function name(string $expression)

    {

        if (! preg_match('/[^\s]+/', $expression, $matches)) {

            throw new InvalidArgumentException('Unable to determine command name from signature.');

        }
<?php         $options = [];



        foreach ($tokens as $token) {

            if (preg_match('/^-{2,}(.*)/', $token, $matches)) {

                $options[] = static::parseOption($matches[1]);

            } else {

                $arguments[] = static::parseArgument($token);
<?php                 return new InputArgument(trim($token, '*'), InputArgument::IS_ARRAY | InputArgument::REQUIRED, $description);

            case str_ends_with($token, '?'):

                return new InputArgument(trim($token, '?'), InputArgument::OPTIONAL, $description);

            case preg_match('/(.+)\=\*(.+)/', $token, $matches):

                return new InputArgument($matches[1], InputArgument::IS_ARRAY, $description, preg_split('/,\s?/', $matches[2]));

            case preg_match('/(.+)\=(.+)/', $token, $matches):

                return new InputArgument($matches[1], InputArgument::OPTIONAL, $description, $matches[2]);
<?php                 return new InputArgument(trim($token, '?'), InputArgument::OPTIONAL, $description);

            case preg_match('/(.+)\=\*(.+)/', $token, $matches):

                return new InputArgument($matches[1], InputArgument::IS_ARRAY, $description, preg_split('/,\s?/', $matches[2]));

            case preg_match('/(.+)\=(.+)/', $token, $matches):

                return new InputArgument($matches[1], InputArgument::OPTIONAL, $description, $matches[2]);

            default:

                return new InputArgument($token, InputArgument::REQUIRED, $description);
<?php                 return new InputOption(trim($token, '='), $shortcut, InputOption::VALUE_OPTIONAL, $description);

            case str_ends_with($token, '=*'):

                return new InputOption(trim($token, '=*'), $shortcut, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, $description);

            case preg_match('/(.+)\=\*(.+)/', $token, $matches):

                return new InputOption($matches[1], $shortcut, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, $description, preg_split('/,\s?/', $matches[2]));

            case preg_match('/(.+)\=(.+)/', $token, $matches):

                return new InputOption($matches[1], $shortcut, InputOption::VALUE_OPTIONAL, $description, $matches[2]);
<?php                 return new InputOption(trim($token, '=*'), $shortcut, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, $description);

            case preg_match('/(.+)\=\*(.+)/', $token, $matches):

                return new InputOption($matches[1], $shortcut, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, $description, preg_split('/,\s?/', $matches[2]));

            case preg_match('/(.+)\=(.+)/', $token, $matches):

                return new InputOption($matches[1], $shortcut, InputOption::VALUE_OPTIONAL, $description, $matches[2]);

            default:

                return new InputOption($token, $shortcut, InputOption::VALUE_NONE, $description);
<?php                 return $this->compileArrayInput($key, $value);

            }



            if (! is_numeric($value) && ! preg_match('/^(-.$|--.*)/i', $value)) {

                $value = ProcessUtils::escapeArgument($value);

            }
<?php             $selectedCommand = select('Which command would you like to run?', $uniqueCommandNames);



            preg_match('/\[(\d+)\]/', $selectedCommand, $choice);



            return (int) $choice[1];

        } else {
<?php     protected function wrapJsonPathSegment($segment)

    {

        if (preg_match('/(\[[^\]]+\])+$/', $segment, $parts)) {

            $key = Str::beforeLast($segment, $parts[0]);



            if (! empty($key)) {
<?php                 throw new RuntimeException('Strings with null bytes cannot be escaped. Use the binary escape option.');

            }



            if (preg_match('//u', $value) === false) {

                throw new RuntimeException('Strings with invalid UTF-8 byte sequences cannot be escaped.');

            }