const regex = /^(xn[-]{2,})?(.*)(\..*)$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(xn[-]{2,})?(.*)(\\..*)$', 'gm')
const str = `domain2=@_.com
my-domain3?\$.com
my---domain3?\$.com
!:domain3?\$.com
;,どるdomain7.com
&)どるdomain6^\`.com
5)my\$\$\$domain4.com
**my--domain5--.com
**my--do--main8--.com
**my---do--main8--.com
xn-\$domain15--.com
xn-\$do--main11--.com
xn\$\$do--main12--.com
ろれっくす.club
xn--domain13--.com
xn---domain14--.com
xn--ztt861f.xn--rhqv96g
xn-----7i8a8a5job0h.xn--1ck2e1b
xn-----5i4a8a4job0h.xn--1ck2e1b
xn-----3i4a8c4hob1h.xn--1ck2e1b
xn-----3i4a8c4hob1h.xo
xn--do--main9--.xn--gdfkg5454--4cx54----)à-è)-(àfglkdfkgldk
xn---do--main10--.com
xn--domain6\`.xn--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