Reputation: 35
I want to create a JavaScript function which replace the word followed by @
Example:
var sample = "Hello @Jon how are you";
var result = myfunction(sample);
// result should be like "Hello xxxxxx how are you"
Here @ symbol also need to be replaced.
Upvotes: 1
Views: 33
Reputation: 67968
@\S+
Try this.Replace by xxx
.See demo.
https://regex101.com/r/sJ9gM7/38
var re = /@\S+/gm;
var str = 'Hello @Jon how are you';
var subst = 'x';
var result = str.replace(re, subst);
Upvotes: 2