wawanopoulos
wawanopoulos

Reputation: 9804

JavaScript : Replace all character by empty after a specific character

I have this String :

var test = "[email protected]";

I would like to replace all character after the "@" character by empty value. I would like to get this String :

var test = "toto"

Upvotes: 2

Views: 53

Answers (2)

maximkou
maximkou

Reputation: 5332

"[email protected]".replace(/@.+$/, '')

Upvotes: 0

nsthethunderbolt
nsthethunderbolt

Reputation: 2097

Try this:

test= test.split('@')[0]

Upvotes: 2

Related Questions