I\'m trying to do something similar with stack overflow\'s rich text editor. Given this text:
[Text Example][1]
[1][http://www.example.com]
I
Here we're using exec method, it helps to get all matches (with help while loop) and get position of matched string.
var input = "A 3 numbers in 333";
var regExp = /\b(\d+)\b/g, match;
while (match = regExp.exec(input))
console.log("Found", match[1], "at", match.index);
// → Found 3 at 2 // Found 333 at 15