I would expect that this
var r = new RegExp(\'\\\\s\\\\@[0-9a-z]+\\\\s\', \'gi\');
applied to this string
1 @bar @foo2 * 112
>
I quickly rigged this up which should do what you want.
var string = "1 @bar @foo2 * 112";
var matches = string.replace(/\s@\w+/gi,"");
console.log(matches)
I could not reproduce your results with that regex, but I did find the final \s would stop the matching of @foo2.
var value = "1 @bar @foo2 * 112";
var matches = value.match(
new RegExp("\\s\\@[0-9a-z]+\\s", "gi")
);
console.log(matches)
This is because the regex can not then match the space in front of @foo which is required as part of the match. I hope this code solves your problem.