doremi
doremi

Reputation: 15329

PHP preg_match URL Segment Not Working

I have a string:

https://domain.tld/123456/api/v1/projects/45242457-foo-bar.json

And I'm trying to match '45242457-foo-bar' using:

preg_match('~"/projects/(.*).json"~', $url, $matches, PREG_OFFSET_CAPTURE);

This keeps returning zero matches. Why?

Upvotes: 0

Views: 337

Answers (1)

John Conde
John Conde

Reputation: 219834

You need to escape your period (and a greedy *):

~"/projects/(.*?)\.json"~

Upvotes: 2

Related Questions