I would expect that this
var r = new RegExp(\'\\\\s\\\\@[0-9a-z]+\\\\s\', \'gi\');
applied to this string
1 @bar @foo2 * 112
"\w" Matches any word character (alphanumeric & underscore). Only matches low-ascii characters (no accented or non-roman characters). Equivalent to [A-Za-z0-9_] Best source to learn : www.regexr.com
Yes, \w
does match latin numbers. \w == [A-Za-z0-9_]
Assuming you want to remove @fooX
, you can use:
console.log("1 @bar @foo2 * 112".replace(/\s@\w+/g, ""));
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.