$re = '/(^(?:\/(_next\/data\/[^\/]{1,}))?(?:\/(?<i18n_locale>(?!_next\/)(en|de)))(?<user_matcher_from_i18n_pattern>\/((?!api|_next\/static|_next\/image|favicon.ico|sitemap.xml|robots.txt).*))(\.json)?[\/#\?]?$)|(^(?<user_matcher_from_base_matcher>\/((?!api|_next\/static|_next\/image|favicon.ico|sitemap.xml|robots.txt).*))[\/#\?]?$)/m';
$str = '/api/some-api-route
/de/some-page-for-de-locale
/some-page-for-default-locale
';
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