regex extract email from strings

前端 未结 7 1465
陌清茗
陌清茗 2020-12-01 16:25

I want to know if by using regular expressions I am able to extract emails from the following strings?

The following RE pattern is .*@.*match with all st

7条回答
  •  無奈伤痛
    2020-12-01 17:10

    Hi this regex is not working for me ......

           let items1 = document.querySelectorAll('h1');
                    items1.forEach((item) => {
                        let pattern = (/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)/gi)
                        if (item.innerHTML.match(pattern)) {
                            results.push({
                                emailId: item.innerHTML
                            });
                        }
                    });
    
    

    This is the tag from which i am getting the text...Just a eg.

     

    "dasd xyz@gmail.com asdas asdsad asdasd"

    This is the object output that I am getting.

    [
      { emailId: 'sadasdsa br@gmail.com' },
      { emailId: 'sadasd br2@gmail.com' },
      { emailId: '"asgdb@gmail.com"' },
      { emailId: '"dasd xyz@gmail.com asdas"' },
      { emailId: 'asgdb@gmail.com' }
    ]
    

提交回复
热议问题