JSFiddle - React, Tailwind, and code Playground

by ozzon91

JavaScript

var text = "[email protected], [email protected] dfsdf <[email protected]> dfsdf <[email protected]>; dfsdf <[email protected]>, dfsdf ([email protected])";
var text2 = "[email protected] dfsdf  dfsdf <[email protected]>;";
var text3 = "[email protected], dddd [email protected], <[email protected]> dfsdf ([email protected])";




function detect_mail_note(text) {
    if(text === undefined) return [];
    var arr = text.split(/[;,]/);
    var cleanarr = [];

    $.each(arr, function(n, el) {
        (function(elem) {
            var res = elem.replace(/((<|\))?[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}(>|\))?)/ig, function(str) {
                return str+'=';
            }).split('=');
            $.each(res, function(n,el) { if(el) cleanarr.push($.trim(el)); });
        })(el);
    
    }); 
    return cleanarr;
}


console.log(detect_mail_note(text));
console.log(detect_mail_note(text2));
console.log(detect_mail_note(text3));