const regex = /^((https|http)\:\/\/){0,}([а-яА-Яa-zA-Z0-9-_]{1,}\.){1,}[-а-яА-Яa-zA-Z0-9_]{1,}(\/[-а-яА-Яa-zA-Z0-9_]{0,}(\.[-а-яА-Яa-zA-Z0-9_]{1,}){0,}){0,}$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^((https|http)\\:\\\/\\\/){0,}([а-яА-Яa-zA-Z0-9-_]{1,}\\.){1,}[-а-яА-Яa-zA-Z0-9_]{1,}(\\\/[-а-яА-Яa-zA-Z0-9_]{0,}(\\.[-а-яА-Яa-zA-Z0-9_]{1,}){0,}){0,}$', 'gm')
const str = `.asd
www
www.com
www.javascript.
www.learn.javascript.ru
https://learn.javascript.ru
https://learn.javascript.ru/
https://learn.javascript.ru/array-ite--_--__ration
https://learn.javascript.ru/array_iteration
https://learn.javascript.ru/array-it-eration/array-it-eration/array-it-eration/
https://learn.javascript.ru/array_iteration/
https://learn.javascript.ru/arrayiteration
https://le-arn.le_arn.learn.learn.learn.learn.javascript.ru/array-iteration/
le-arn.le_arn.learn.learn.learn.learn.javascript.ru/array-itera345345tion/
мвываываывад.рф
мвкд.рф
сайтсрусскимибуквам.рф
мвываываыв ад.рф
https://мвд.рф
www.url
https://preprodbpm.ecommpay.com/Nui/ViewModule.aspx
https://preprodbpm.ecommpay.com/0/ViewModule.aspx
https://preprodbpm.ecommpay.com/ViewModule.aspx
https://preprodbpm.ecommpay.com/ViewModule.`;
// 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