查找在URL中更改位置的字符串[duplicate]

I have a URL which changes it position sometime

my urls look like

https://video.twimg.com/ext_tw_video/841791481534803968/pu/vid/320x180/egCAExYQdRBw08fb.mp4
https://video.twimg.com/ext_tw_video/841791481534803968/pu/vid/1280x720/GVsCGddpL9QoO4_B.mp4
https://video.twimg.com/ext_tw_video/841791481534803968/pu/vid/640x360/33qcUEzFw-WS0inJ.mp4

In these url i need to extract "320x180" , "1280x720" , "640x360" There are more and the list goes on.

Plus the link changes like sometimes there is no /pu/vid/ part in the url. I tried with Php explode function but as position changes. Its hard to find them. for example

https://video.twimg.com/ext_tw_video/640x360/pu/vid/841791481534803968/33qcUEzFw-WS0inJ.mp4

for the constant part i was using this code

$breaker=(explode("/",$video->url));
$quality = $breaker[6];

But since they change places and their values differ. Is there any different approach to it? Also if the values stay same then how can i extract the URL of the video quality

like if the script finds the quality is 1280x720 then it will give me the url.and will loop through them to find different static video qualities?

https://video.twimg.com/ext_tw_video/841791481534803968/pu/vid/1280x720/GVsCGddpL9QoO4_B.mp4
</div>

You should just be able to use a preg_match() or preg_match_all() on the regex \d+x\d+, which matches an x preceded and followed by any number of digits.

preg_match("/\d+x\d+/", $input_line, $output_array);
preg_match_all("/\d+x\d+/", $input_lines, $output_array);

This can be seen working on Regex101 here and PHPLiveRegex here.

You could be a little more specific and use (?<=\/)\d{1,4}x\d{1,4}(?=\/), which ensures that there are between 1 and 4 digits in each group, and that the target string is enclosed by two /, though this is likely unnecessary.