const regex = /(?:http|https):\/\/((?:[\w-]+)(?:\.[\w-]+)+)(?:[\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?:http|https):\\\/\\\/((?:[\\w-]+)(?:\\.[\\w-]+)+)(?:[\\w.,@?^=%&:\\\/~+#-]*[\\w@?^=%&\\\/~+#-])?', 'gm')
const str = `https://developer.mozilla.org/es/
http://www.es.pornhub.com/
http://es.cumlouder.com/?nats=MTkzOC4xLjIuMi4wLjAuMC4wLjA
http://www.pornotube.com/orientation/straight/home/page/1
http://rubias19.com/
http://www.elreyx.com/
http://www.puritanas.com/
http://www.xvideos.com/
http://es.xhamster.com/
http://www.redtube.com/
http://es.cam4.com/
https://es.chaturbate.com/
http://new.bangbros.com/home.htm
http://www.brazzers.com/home/?nats=NDc1NzAzOjQ5MzoyNA,0,0,0,0
http://www.petardas.com/
http://www.poringa.net/
http://foxtube.com/
http://www.tubewolf.com/
http://www.youporn.com/
http://www.putalocura.com/
http://www.serviporno.com/
http://www.toropornohd.com/
http://www.aztepajas.com/
http://pornfun.com/`;
// 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