MobileDetect::match()publicWC 1.0

Some detection rules are relative (not standard), because of the diversity of devices, vendors and their conventions in representing the User-Agent or the HTTP headers.

This method will be used to check custom regexes against the User-Agent string.

Method of the class: MobileDetect{}

No Hooks.




$MobileDetect = new MobileDetect();
$MobileDetect->match( $regex, $userAgent ): bool;
$regex(string) (required)
Default: null

MobileDetect::match() code WC 9.0.1

public function match(string $regex, string $userAgent = null): bool
    if (!\is_string($userAgent) && !\is_string($this->userAgent)) {
        return false;

    $match = (bool) preg_match(
        sprintf('#%s#is', $regex),
        (false === empty($userAgent) ? $userAgent : $this->userAgent),
    // If positive match is found, store the results for debug.
    if ($match) {
        $this->matchingRegex = $regex;
        $this->matchesArray = $matches;

    return $match;