const regex = /^[^.\n]*[^\/\n]*\.\K[^\/\n]+/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^[^.\\n]*[^\\\/\\n]*\\.\\K[^\\\/\\n]+', 'gm')
const str = `https://www.example.org/
http://example.com/
ca.gov
http://blade.example.com/bikes/airplane.php
http://alarm.example.com/
smugmug.com
shop-pro.jp
https://example.org/
qq.com
pcworld.com
symantec.com
360.cn
http://example.com/?brother=bike
http://www.example.com/behavior/bead.php
army.mil
https://example.com/boy/bedroom.php
https://example.com/
https://www.example.com/brother?activity=believe
https://www.example.net/achiever/bottle.html
http://believe.example.com/bit?bait=base&bone=ball
aboutads.info
http://www.example.com/
http://www.example.edu/afternoon
livejournal.com
http://border.example.com/box/afterthought
oaic.gov.au
https://www.example.edu/base.php
house.gov
smh.com.au
http://www.example.edu/
https://www.example.org/
lycos.com
https://border.example.com/?bridge=basket&blood=animal
hibu.com
http://example.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