const regex = /([\:][\/]{0,2})[\w\-]+([\@]|[\.])?([\w\-]+[\.]){0,}([\w\-]+)?([\:][\d]+)?[\/]?/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('([\\:][\\\/]{0,2})[\\w\\-]+([\\@]|[\\.])?([\\w\\-]+[\\.]){0,}([\\w\\-]+)?([\\:][\\d]+)?[\\\/]?', 'g')
const str = `https://user_test-teste@regex101.com:80/
http://localhost:80/
https://tools.ietf.org/html/rfc3986#page-7
https://translate.google.com.br/#en/pt/that%20what
https://www.google.com.br/search?client=firefox-b&biw=1920&bih=1001&q=overload+inexistent+property+php&oq=overload+inexistent+property+php&gs_l=psy-ab.3..33i22i29i30k1.36919.57166.0.57324.38.36.2.0.0.0.682.3958.14j18j5-1.33.0....0...1.1.64.psy-ab..3.27.3324...0j35i39k1j0i131k1j0i67k1j0i10k1j0i22i30k1j33i160k1j33i21k1.m5dBRh4nQ-I`;
// 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