JSFiddle - React, Tailwind, and code Playground
HTML
<textarea id="test">
http://www.dailymotion.com/video/x44lvd_rates-of-exchange-like-a-renegade_music
http://www.dailymotion.com/video/x44lvd
http://www.dailymotion.com/hub/x9q_Galatasaray
http://www.dailymotion.com/login?restricted_action=1&urlback=%2Fupload
http://www.dailymotion.com/hub/x9q_Galatasaray#video=xjw21s
http://www.dailymotion.com/video/xn1bi0_hakan-yukur-klip_sport
http://dai.ly/x44lvd
</textarea>
<pre id="result"></pre>
CSS
textarea {
width: 800px;
height: 300px;
}
JavaScript
function getIds(str) {
var ret = [];
var re = /(?:dailymotion\.com(?:\/video|\/hub)|dai\.ly)\/([0-9a-z]+)(?:[\-_0-9a-zA-Z]+#video=([a-z0-9]+))?/g;
var m;
while ((m = re.exec(str)) != null) {
if (m.index === re.lastIndex) {
re.lastIndex++;
}
ret.push(m[2]?m[2]:m[1]);
}
return ret;
}
var area = document.getElementById('test');
var result = document.getElementById('result');
function search() {
var ids = getIds(area.value);
result.innerHTML = JSON.stringify(ids);
}
area.addEventListener('input', search);
search();