const regex = /^(https?:\/\/)?([а-я0-9_-]{1,32}|[a-z0-9_-]{1,32})\.([а-я0-9_-]{1,8}|[a-z0-9_-]\S{1,8})$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(https?:\\\/\\\/)?([а-я0-9_-]{1,32}|[a-z0-9_-]{1,32})\\.([а-я0-9_-]{1,8}|[a-z0-9_-]\\S{1,8})$', 'gm')
const str = `/********************** yes *****************/
http://yandex.ru
http://asdasd.ru
sdfsdf.ru
http://sdfsdf.ru/sadasds-sadsad/sadsad
http://sdfsdf.ru/sadasds-sadsad/sadsad?page=2
http://sdfsdf.ru/sadasds-sadsad/sadsad?page=2&other=1
sdfsdf.ru/sadasds-sadsad/sadsad?page=2&other=1
http://sdfsdf.ru/sadasds/sadsad?page=2&other=1
https://regex101.com/r/tM7Pmr/1
http://regexpres.narod.ru/calculator.html
http://regexpres.narod.ru/calculator.htm
http://regexpres.narod.ru/calculator.php
http://regexpres.narod.ru/index.php
http://regexpres.narod.ru/index
https://jsfiddle.net/3b0khwhasd6/
https://lenta.ru/articles/2017/03/06/ruvlogs/
https://www.youtube.com/watch?v=PDxVcTWVIck
www.youtube.com/watch?v=PDxVcTWVIck
https://zakon.ru/blog/2017/03/06/delo_o_denezhnyh_generatorah_i_udobnom_sude__p-v_protiv_ikea_opredelenie_skgd_vs_ot_17012017_36-kg16
https://zakon.ru/konstitucionnyj_sud_rf
zakon.ru/blog/2017/03/06/delo_o_denezhnyh_generatorah_i_udobnom_sude__p-v_protiv_ikea_opredelenie_skgd_vs_ot_17012017_36-kg16
https://zakon.ru/konstitucionnyj_sud_rf
/********************** not *****************/
4234czxc
sdfsdf
sdsad.rturturturt/fsdfsd@sd`;
// 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