Regular expressions help required

in #steemgig7 years ago

To extract "w6OyOZXoq14" from the string https://www.youtube.com/watch?v=w6OyOZXoq14 we can use the below preg_match in php.

preg_match('/^https?:\/\/(www\.)?((?!.*list=)youtube\.com\/watch\?.*v=|youtu\.be\/)(?<id>[0-9A-Za-z_-]*)/', $input, $matches);
return isset($matches['id']) ? $matches['id'] : FALSE;


Similarly I need to extract "dollarvigilante/4iknjlwx" from "https://dtube.video/#!/v/dollarvigilante/4iknjlwx"

Can somebody lend a quick helping hand? I generally head to stackoverlfow for these kinds of queries. Trying to see if it can work on steemit itself.

Sort:  
/* Supported schemes:
 * 'https://dtube.video/#!/v/dollarvigilante/4iknjlwx'
 * 'https://dtube.video/v/dollarvigilante/4iknjlwx'
 */
$input = 'https://dtube.video/#!/v/dollarvigilante/4iknjlwx';
preg_match('/^https?:\/\/+(?:www\.)?dtube.video\/*(?:#!)?\/+v\/+(?<fullid>(?<userid>[a-z][a-z0-9\-]{1,14}[a-z0-9](?:\.[a-z][a-z0-9\-]{1,10}[a-z0-9])*)\/(?<videoid>[a-z0-9_\-]+))/i', $input, $matches);

// return "dollarvigilante/4iknjlwx"
return isset($matches['fullid']) ? $matches['fullid'] : false; 

// return "dollarvigilante"
return isset($matches['userid']) ? $matches['userid'] : false;

// return "4iknjlwx"
return isset($matches['videoid']) ? $matches['videoid'] : false;

Lovely that was handy. Thanks for the quick response.

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.028
BTC 61651.16
ETH 2369.36
USDT 1.00
SBD 2.50