var reg = /users\.\$+[^]+_[1-9]/,
text = "E11000 duplicate key error index: test.users.$username_1 dup key";
console.log(reg.exec(text));
["users.$username_1", index: 39, input: "E11000 duplicate key error index: test.users.$username_1 dup key"]
var reg = /^.*users\.\$(\S+).*$/,
text = "E11000 duplicate key error index: test.users.$username_1 dup key";
console.log(text.replace(reg, '$1'));