How to extract the desired part from the links?

There are several types of links to clips twitch
https://clips.twitch.tv/SneakyFantasticMoonLitty
or so
https://www.twitch.tv/lex4tor88/clip/SneakyFantasticMoonLitty?filter=clips&range=all&sort=time

You need to pull the part in bold. Tell me how.
April 4th 20 at 00:38
3 answers
April 4th 20 at 00:40
Solution
$string = '
https://clips.twitch.tv/SneakyFantasticMoonLitty123
or so
https://www.twitch.tv/lex4tor88/clip/SneakyFantasticMoonLitty456?filter=clips&range=all&sort=time
';

if(preg_match_all('/twitch\.tv\/(?:[^\/]+\/clip\/)?([0-9a-z]+)/uis', $string, $matches)) {
print_r($matches[1]);
}
April 4th 20 at 00:42
preg_match('~(?<=\/)\w+(?=\?|$)~', $str, $match);
$result = $match[0];
Only works it without checking for domain. Thank you! - Candice commented on April 4th 20 at 00:45
@Candice, that is, to clearly formulate the essence of their problems you don't know about the "test domain" speech in the original question was not. - dale_Kub commented on April 4th 20 at 00:48
April 4th 20 at 00:44
Of course, let's regexps to do the standard things
<?php
$url = 'https://www.twitch.tv/lex4tor88/clip/SneakyFantasticMoonLitty?filter=clips&range=all&sort=time';
var_dump(
 basename(parse_url($url, PHP_URL_PATH))
);

p.s
"You have a problem. You decided to use regular expressions to solve it. Now you have two problems.”
I haven't used so far that even regular expression) - Candice commented on April 4th 20 at 00:47

Find more questions by tags PHP