Skip to content

Function preg_match not working properly #26

@WillyReyno

Description

@WillyReyno

Method preg_match doesn't seem to be working properly after installing Safe.

I made a regex to split spotify URL and retrieve the id. Here is my code which is working when I remove Safe's use function :

public function getTrackIdFromUrl(string $url): ?string
    {
        $spotifyRegex = "/https?:\/\/(?:embed\.|open\.)(?:spotify\.com\/)(?:track\/|\?uri=spotify:track:)((\w|-){22})/";
        preg_match($spotifyRegex, $url, $matches);
        return $matches[1] ?? null;
    }

For the url https://open.spotify.com/track/0nCqpKBrvDchO1BIvt7DTR?si=iLUKDfkLSy-IpnLA7qImnw the return of $matches[1] should be 0YCRJcAXQ3NSfKN1x1IXK3.
With Safe, $matches returns null.

Thank you for the awesome lib :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions