const regex = /http[s]?:\/(?:\/[^\/]+){1,}(?:\/[А-Яа-яёЁ\w ]+\.[a-z]{3,5}(?![\/]|[\wА-Яа-яёЁ]))/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('http[s]?:\\\/(?:\\\/[^\\\/]+){1,}(?:\\\/[А-Яа-яёЁ\\w ]+\\.[a-z]{3,5}(?![\\\/]|[\\wА-Яа-яёЁ]))', 'gm')
const str = `https://i.imgur.com/pO5SM73.png
https://i.imgur.com
https://i.imgur.ru/a.gdb
http://bse.sci-lib.com/article089432.html
http://megabook.ru/article/Кошка Собака.png
http://architect.academic.ru/3502/Мансарда
http://megabook.ru/article/%D0%90%D0%BD%D1%82%D0%B0%D0%B1%D0%BB%D0%B5%D0%BC%D0%B5%D0%BD%D1%82
http://bse.sci-lib.com/a_pictures/17/10/265722250.jpg
http://dic.academic.ru/dic.nsf/stroitel/4
<brbrbr> okk http://fooo-bar.com/more/than/file.exe fdfdfs http://fooo-bar.com/more/than/fil2.exe
http://a.org/ddddd.ddddd
http://a.org/ddddd.dddddв`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions