const regex = /^(?=.{6,284}$)[^\W_](?:[+\w.-]*[^\W_])?@[^\W_](?:\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.|(?:[\w-]+\.)+)(?:[a-zA-Z]{2,13}|[0-9]{1,3})\]?$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(?=.{6,284}$)[^\\W_](?:[+\\w.-]*[^\\W_])?@[^\\W_](?:\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.|(?:[\\w-]+\\.)+)(?:[a-zA-Z]{2,13}|[0-9]{1,3})\\]?$', 'gm')
const str = `.abc@ornekeposta.com
_abc@ornekeposta.com
9abc.@ornekeposta.com
!@ornekeposta.com
a!@ornekeposta.com
ö@ö@.ö
#4+^%+@göl.çöz
!'^+%&&/)=?:_@^+%+^&%(.+%^+%%+/&%&.com
a_@a.aa
21322534@435345345.4353.4543
a@aa.aa
1@12.co
a.1@555555.com
a@ornekeposta.com
9abc@ornekeposta.com
abc@ornekeposta.org.tr
m@it.ai.tr.cz.ru.dart
name@surname.aero
AAAA@AAA.AA
deneme+tag@deneme.com
very-important@person.international
istanbul-istanbul-istanbul-istanbul-istanbul-istanbul-istanbul-istanbul-istanbul-istanbul-istanbul-istanbul-istanbul-istanbul-istanbul-istanbul-istanbul-istanbul-istanbul.istanbul.istanbul.istanbul+istanbul@4istanbul.istanbul-istanbul-istanbul-istanbul-istanbul.istanbul.ista.istanbul
`;
// 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