The match() method retrieves the matches when matching a string against a regular expression.

@param string $regexp
@param int $flag
@param int $offset
@return array
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;
    }
651452
public function matchPath($regexp)
	{
		if (substr($regexp, 0, 1) == '@') {
			$this->route_name = substr($regexp, 1);
		} else {
			parent::matchPath($regexp);
		}
	}
523795
private static function PrepareRegexFlags( $flagString )
	{
		// The flag string can only contain s,m,i and/or x
		$result = preg_match( "/[^smix]+/", $flagString);
		if ( $result )
		{
			throw XPath2Exception::withErrorCodeAndParam( "FORX0001", Resources::InvalidRegularExpr, "$flagString" );
		}

		return $flagString;
	}
654185
protected function matchSetextLines()
	{
		if ($this->text->indexOf('-') === false && $this->text->indexOf('=') === false)
		{
			return;
		}

		// Capture the any series of - or = alone on a line, optionally preceded with the
		// angle brackets notation used in blockquotes
		$regexp = '/^(?=[-=>])(?:> ?)*(?=[-=])(?:-+|=+) *$/m';
		if (!preg_match_all($regexp, $this->text, $matches, PREG_OFFSET_CAPTURE))
		{
			return;
		}

		foreach ($matches[0] as list($match, $matchPos))
		{
			// Compute the position of the end tag. We start on the LF character before the
			// match and keep rewinding until we find a non-space character
			$endPos = $matchPos - 1;
			while ($endPos > 0 && $this->text->charAt($endPos - 1) === ' ')
			{
				--$endPos;
			}

			// Store at the offset of the LF character
			$this->setextLines[$matchPos - 1] = [
				'endLen'     => $matchPos + strlen($match) - $endPos,
				'endPos'     => $endPos,
				'quoteDepth' => substr_count($match, '>'),
				'tagName'    => ($match[0] === '=') ? 'H1' : 'H2'
			];
		}
	}
825024
public function match(string $subject, $flags = 0, $offset = 0): int
	{
		$this->clean();
		return preg_match($this->pattern, $subject, $this->last_match, $flags, $offset);
	}
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;
        }
    }
1128117
function match(regexp) {
      var O = defined(this);
      var fn = regexp == undefined ? undefined : regexp[MATCH];
      return fn !== undefined ? fn.call(regexp, O) : new RegExp(regexp)[MATCH](String(O));
    }
1332673
public static function sanitizeRegExp($regExp)
    {
        $pattern_parts = explode($regExp{0}, trim($regExp));
        $pattern_last = sizeof($pattern_parts) - 1;
        $pattern_parts[$pattern_last] = str_replace('e', '', $pattern_parts[$pattern_last]);
        
        return implode($regExp{0}, $pattern_parts);
    }
188476
private function matchUri(string $regex, string $uri): ?array
    {
        if (preg_match_all('/' . $regex . '/', $uri, $uriMatches)) {
            $uriMatches = array_filter($uriMatches, function ($key) {
                if (is_string($key)) {
                    return true;
                }

                return false;
            }, ARRAY_FILTER_USE_KEY);

            $uriMatches = array_map(function ($match) {
                return $match[0];
            }, $uriMatches);

            return $uriMatches;
        }

        return null;
    }
902551
public function extractFlags($flag)
    {
        $flags = [];

        for ($i = 0; $i <= 26; $i++) {
            if ((int) $flag & (1 << $i)) {
                array_push($flags, 1 << $i);
            }
        }

        return $flags;
    }
1081855
private static function PrepareRegexPattern( $pattern, $flagString )
	{

		// Check the pattern does not include a back-reference in a character class
		$result = preg_match( "/\[.*?\\\\\d+.*?\]/", $pattern );
		if ( $result )
		{
			throw XPath2Exception::withErrorCodeAndParam( "FORX0002", Resources::InvalidRegularExpr, "$pattern/$flagString" );
		}

		// If one of the flags is x then need to remove whitespace not in character classes
		// PCRE will not remove escaped spaces when the x flag is used but XPath expects them to be removed
		if ( strpos( $flagString, "x" ) !== false )
		{
			$results = preg_match_all( "/((?<expr>[^[]*)(?<chars>\[.*?\])?)/", $pattern, $matches );
			for ( $i = 0; $i < $results; $i++ )
			{
				$match = $matches['expr'][ $i ];
				if ( empty( $match) ) continue;
				$result = preg_replace( "/((?![\r\n])\s)+/", "", $match );
				if ( $match == $result ) continue;
				$pattern = str_replace( $match, $result, $pattern );
			}
		}

		// If there is a back-reference need to add an empty comment to separate the
		// back-reference number from any following digit(s) and repeat for all back-references
		// $groups = substr_count( $pattern, "(" );
		// This pattern counts the parentheses that are not escaped by just one backslash (two is OK)
		$groups = preg_match_all( '/\\\\\\\\\(|\((?<!\\\\\()/', $pattern );
		if ( $groups )
		{
			// Get a list of all the back reference numbers
			$result = preg_match_all( "/\\\\(\d(\d?))*/", $pattern, $matches );
			if ( $result )
			{
				// $result2 = preg_match_all( "/\((([^()]+)|(?R))*\)/", $pattern, $parens );

				// Grab the valid values
				$values = array();
				foreach ( array_filter( $matches[1] ) as $key => $match )
				{
					$potentialValues = array();
					while ( strlen( $match ) > 0 )
					{
						$potentialValues[] = $match;
						$match = substr( $match, 0, strlen( $match ) - 1 );
					}

					sort( $potentialValues );
					$error = false;
					while ( count( $potentialValues ) )
					{
						$value = array_pop( $potentialValues );

						// Find the match(es) in the string and count the number of opening parentheses until that point
						$pos = strpos( $pattern, $value );

						// $matchgroupsOpen = substr_count( $pattern, "(", 0, $pos );
						// This horrible list of backslashes occurs because the regex escape char is \ and the same for PHP.
						// So every real backslash has to be quadrupled. Here's what the regex will look like outside PHP
						// 	/\\\\\(|\((?<!\\\()/
						$matchgroupsOpen = preg_match_all( '/\\\\\\\\\(|\((?<!\\\\\()/', substr( $pattern, 0, $pos ) );

						// If there are no groups throw an exception
						$error = ! $matchgroupsOpen || $matchgroupsOpen < $value;

						if ( ! $error )
						{
							// $matchgroupsClosed = substr_count( $pattern, ")", 0, $pos );
							$matchgroupsClosed = preg_match_all( '/\\\\\\\\\)|\)(?<!\\\\\))/', substr( $pattern, 0, $pos ) );

							// If reference is in a capture group its an error
							$error = ! $matchgroupsClosed || $matchgroupsClosed != $matchgroupsOpen || $matchgroupsClosed < $value;

							if ( $error ) continue;
							// This is the longest number
							$values[] = $value;
							break;
						}
					}

					if ( $error )
					{
						throw XPath2Exception::withErrorCode( "FORX0002", Resources::FORX0002 );
					}
				}

				// Make sure the back-reference numbers are valid given the list of capture groups available
				$validValues = array_intersect( $values, range( 1, $groups ) );

				// Sort them in descending order so the longest number is handled first.
				// This way \1 and \11 are handled correctly.
				// BMS Not sure this is necessary.
				rsort( $validValues );
				foreach ( $validValues as $value )
				{
					// Replace the number but only if the number is not already followed by an empty comment
					$pattern = preg_replace( "/\\\\($value)(?!\d?\(\?\#\))/", "\\\\$1(?#)", $pattern );
				}
			}
		}

		// Check to see if there are any character classes that specify character subtraction
		// If so, convert to a negative lookahead
		$results = preg_match_all( "/\[(?<chars>((.*)?(.-.))+)-(?<sub>\[(.*|.*?(.-.))+\])\]/", $pattern, $matches );
		if ( $results )
		{
			for ( $i = 0; $i < $results; $i++ )
			{
				$chars = $matches['chars'][ $i ];
				$sub = $matches['sub'][ $i ];
				$x = "(?!$sub)[$chars]";

				$pattern = str_replace( $matches[ $i ], $x, $pattern );
			}
		}

		// Replace common unicode character classes
		$pattern = str_replace( "{IsBasic", "{", $pattern );

		return $pattern;
	}
763579
static public function generate($regExp)
    {
        if (@preg_match('/'.$regExp.'/', '') === false) {
            throw new RegExpNotValidException($regExp);
        }
        self::bootstrap();
        self::$typesFound = array();
        while (strlen($regExp) > 0) {
            foreach (self::$expressions as $type) {
                if ($type->isValid($regExp)) {
                    Debug::setMessage($type->getName() . ' ' . $type->getMatch());
                    self::$typesFound[] = clone $type;
                    $lengthOfMatch = strlen($type->getMatch());
                    $regExp = substr($regExp, $lengthOfMatch);

                    break;
                }
            }
        }

        return self::outPut();
    }
1264894
public function regexp($regexp)
    {
        $results = [];
        foreach ($this->columns as $name => $column) {
            $column = trim($column);
            if (preg_match($regexp, $name)) {
                $results[] = $name;
            }
        }

        return new Result($results, $this->columns);
    }
947932
public function pregValues($pattern, $defaultResult = null, $flags = 0)
    {
        $result = preg_grep($pattern, array_values($this->target), $flags);

        return $result ? array_values($result) : $defaultResult;
    }
1099133
protected static function getNamedCaptures($str, $regexp, $map)
	{
		if (!preg_match($regexp, $str, $m))
		{
			return [];
		}

		$values = [];
		foreach ($map as $i => $k)
		{
			if (isset($m[$i]) && $m[$i] !== '')
			{
				$values[$k] = $m[$i];
			}
		}

		return $values;
	}
438431
function regexp($pattern, $flags = null) {
        $regexp['pattern'] = $pattern;
        if ($flags) $regexp['flags'] = $flags;
        $this->data['regexp'] = $regexp;
        return $this;
    }
1074919
public static function grep(array $arr, string $pattern, int $flags = 0): array
    {
        return Strings::pcre('\preg_grep', [$pattern, $arr, $flags]);
    }