0

Scenario

Recently I extracted emails from 430 different html webpages of organizations with regex but some organizations had multiple emails and here's what the mess looks like

Input

   Organization 2

     info@something.org.au more@something.com market@gmail.com single@noidea.com human@myplace.com south@north.com darlings@mall.com 


   Organization 3

  headmistress@money.com head@skull.com  

What I want
The very first email of these organizations is the important email. Is there any way regex can select everything after the first whole word and I can use Notepad++'s "Replace All" to remove it?

Output(Something like this)

   Organization 2

     info@something.org.au


   Organization 3

  headmistress@money.com

2 Answers2

1

To get your expected output, use this pattern:

/^.*?@[^ ]+|^.*$/gm

Online Demo

Shafizadeh
  • 9,086
  • 10
  • 43
  • 80
  • 1
    Thanks Shafizadeh :) – Radioactive Coffe Jul 28 '16 at 05:35
  • I hope I'm not asking for a lot but I'm very keen to learn regular expressions like this, do you have any links/resources you suggest I should learn from to become as amazing as you are? – Radioactive Coffe Jul 28 '16 at 05:38
  • @RadioactiveCoffe You are welcome .. You can start learning with [this](http://stackoverflow.com/questions/4736/learning-regular-expressions). By the way [this](https://regex101.com/) is the best regex tester in my opinion *(also it can be even as a good tutorial too)*. – Shafizadeh Jul 28 '16 at 06:45
0
  • step 1:
    first you have to keep all email address in a variable as string.
  • step 2:
    split your string to array
  • step 3:
    get your first email id based on array index.

check the example code below:

    var emailIds = "info@something.org.au more@something.com market@gmail.com,  single@noidea.com human@myplace.com south@north.com darlings@mall.com";

    var emailInArray = emailIds.split(' ');

    console.log(emailInArray[0]) //info@something.org.au;
Sridhar
  • 128
  • 1
  • 10