const regex = /(url\s\d+[.]\d+[.]\d+[.]\d+[:](http|https|ftp).*)/gi;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(url\\s\\d+[.]\\d+[.]\\d+[.]\\d+[:](http|https|ftp).*)', 'gi')
const str = `URL 123.45.67.8:http://www.google-analytics.com/r/collect?v=1&_v=j41&a=1071188231&t=pageview&_s=1&dl=http%3A%2F%2Fm.sherdog.com%2F&ul=en-us&de=UTF-8&dt=Sherdog.com%3A%20UFC%2C%20Mixed%20Martial%20Arts%20(MMA)%20News%2C%20Results%2C%20Fighting&sd=32-bit&sr=320x480&vp=320x460&je=0&_utma=236548035.1293902652.1385044241.1442
URL 123.34.45.7:http://captive.apple.com/hotspot-detect.html`;
// 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