$re = '/((a-zA-Z){2}\/)?(app|album|book|audiobook|author|movie|movie-collection|studio|artist|developer|music-video|video|podcast|tv-season|tv-show)\/((a-zA-Z0-9\-)*\/)?(id)?(0-9)*/mi';
$str = '//bad link examples from past traffic:
/bkp.sql.tar.gz
/bkp.sql.tar.gz
/core/modules/system/tests/modules/error_service_test/src/Logger
/_get/spool/kjax/rrmjaxfl.923e30d17ca8f0b37a489c818eae0577.txt.js
/_get/spool/kjax/rrmjaxfl.923e30d17ca8f0b37a489c818eae0577.txt.php
/?AT=10l9IM&i=469623817&uo=4/cat ../../../../../../../../etc/passwd
/?at=11lK2U/..///////..////..//////etc/passwd&forcetoken=11lK2U/..///////..////..//////etc/passwd
//can\'t do anything with these, no point in calling us
/subscribe?app=music&at=1001lLm9&itscg=30200&itsct=addotnet&ct=884-11165151
/lookup?id=622463230
/search?term=You\'re%20Not%20There%20-%20Lukas%20Graham&entity=song&media=music&country=DK&limit=1
/WebObjects/MZSearch.woa/wa/advancedSearch?s=143443&partnerId=2003&affToken=www.last.fm&at=10l3Sh&artistTerm=Schmetterlinge&songTerm=Wer+schreibt+die+Geschichte?
/actuator/jolokia
//supported by GeniusLink
/app/id1235
/us/app/id1235
/us/app/among-us/id1351168404
/us/app/1password-7-password-manager/id1333542190?mt=12
/us/book/dune/id597944491
/us/audiobook/a-promised-land-unabridged/id1540585069
/us/author/c.j.-archer/id421351544?mt=11
/us/movie/tenet/id1538251548
/us/movie-collection/the-lord-of-the-rings-extended-editions-bundle/id1537502630
/us/studio/pixar/id81758682
/us/album/willow/1544268281?i=1544268298
/us/album/evermore/1544268281
/us/artist/taylor-swift/159260351
/us/music-video/i-dont-care-bonus-video/1445881948
/au/video/id254295715?mt=5
/us/podcast/the-chernobyl-podcast/id1459712981
/us/tv-season/freight-trains-and-monsters/id1514426968?i=1520794309
/us/tv-season/yellowstone-season-3/id1514426968
/ca/tv-show/come-fly-with-me/id410581843
/us/developer/tapbots/id293642940
/video/histories/id253624330?uo=5&AT=10l9IM
/video/course-you-know-this-means/id665084512?uo=5&AT=10l9IM
/artist/jaime-urrutia/id27431058?uo=5&at=1010l34Ub&ct=cart&app=music
/app/noteshelf-2/id1271086060?mt=8&uo=4&at=11l9z8
/album/1552222070?uo=4&app=itunes&at=1l3vpUI&lId=22814830&cId=none&sr=6&src=Linkfire&itscg=30440&itsct=catchall_p6&ct=LFV_44d9b6dc091636bfbe66b473b4135330&ls=1
';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php