1. The existing PHP code implementation is as follows
// $va = 'internal://all_collectionss/';
$va = 'internal://all_collectionss/1';
$matches = [];
if (preg_match('#internal://([^/]+)s/([^/]+)#', $va, $matches)) {
$resource = strtolower($matches[1]);
$resourceId = $matches[2];
}
2. Open https://regex101.com/ , the match is successful, and the result is as follows. As shown in Figure 1

Match 1 0-29 internal://all_collectionss/1
Group 1 11-26 all_collections
Group 2 28-29 1
3. Now we expect internal://all_collectionss/ to also match. Prompt: Your regular expression does not match the subject string. As shown in Figure 2

Your regular expression does not match the subject string.
Try launching the debugger to find out why.
4. Characters with special meanings in regular expressions are called metacharacters. Commonly used metacharacters include: * quantifier, matches 0 or more times; + quantifier, matches 1 or more times. Since an empty string is allowed after the final /, we should change + to *. #internal://([^/]+)s/([^/]*)# matches successfully in both cases. As shown in Figure 3 and Figure 4


5. The final PHP code implementation is as follows
// $va = 'internal://all_collectionss/';
$va = 'internal://all_collectionss/1';
$matches = [];
if (preg_match('#internal://([^/]+)s/([^/]*)#', $va, $matches)) {
$resource = strtolower($matches[1]);
$resourceId = $matches[2];
}
