简体   繁体   中英

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?

你需要逃避你的时期(和贪婪的*):

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM