With javascript, how do we remove the @gmail.com or @aol.com from a string so that what only remains is the name? 

```
var string = "johndoe@yahoo.com";

```

Will be just "johdoe"? I tried with split but it did not end well. thanks.
['https://Stackoverflow.com/questions/18371339', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2522342/']
You can try with the replace() and regular expression. You can read more about replace() using regex [here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)

```
var myEmail = 'johndoe@yahoo.com';
var name= myEmail.replace(/@.*/, "");
console.log(name);

```

This returns the string before @
This simple regex will do the needful.  

`/^.*(?=@)/g`.

Example:

```
"johndoe@yahoo.com".match(/^.*(?=@)/g); // returns Array [ "johndoe" ]

```