Extract all email addresses from bulk text using jquery

前端 未结 7 1551
北海茫月
北海茫月 2020-11-28 06:09

I\'m having the this text below:

sdabhikagathara@rediffmail.com, \"assdsdf\" , \"rodnsdfald ferdfnson\" 

        
7条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 06:52

    The bellow function is RFC2822 compliant according to Regexr.com

    ES5 :

    var extract = function(value) {
       var reg = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/g;
       return value && value.match(reg);
    }
    

    ES6 :

    const reg = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/g
    const extract = value => value && value.match(reg)
    

    Regexr community source

提交回复
热议问题