const regex = /^(htt|www\.)(?!.*\1).*$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(htt|www\\.)(?!.*\\1).*$', 'gm')
const str = `http://www.sample.com
https://www.sample.com
http://www.sample.com/xyz
www.sample.com
www.sample.com/xyz/#/xyz
sample.com
www.sample.com
mofiz.com
kolim.com
www.murikhao.www.sample.com
http://murihao.www.sample.com
http://www.sample.com/xyz?abc=dkd&p=q&c=2
www.sample.gov.bd
www.sample.com.en
www.sample.vu
https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE1t5OJ?ver=c8b4
https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE1t5OJ?ver=c8b4https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE1t5OJ?ver=c8b4
www.msft.com
http://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE1XqlR?ver=b1bchttp://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RW6fET?ver=80af
http://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE1XDkS?ver=6779https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE1Etgg
`;
// 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