const regex = /^(http|https):\/\//gmi;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(http|https):\\\/\\\/', 'gmi')
const str = `https://images.unsplash.com/photo-1441742917377-57f78ee0e582?q=80&fm=jpg&s=a79e8a2beba8b3a1ad251798a9024d8b
http://stackoverflow.com/questions/10625497/regex-to-check-if-http-or-https-exists-in-the-string
Http://thepaperwall.com/wallpaper.php?view=4d119619f49377f7aacc7efe564c3bf890b3c063
hTTp://thepaperwall.com/wallpapers/girls/big/big_4d119619f49377f7aacc7efe564c3bf890b3c063.jpg`;
// 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