Q:

Regular Expression for any number excluding specific numbers

I'd like to make a regular expression that captures every integer (both positive and negative) as long as it is not one of the following: -2, -1, 0, 1, 2, or 10.
So these should match: -11, 8, -4, 11, 15, 121, 3, etc.
So far, I have this regex: /-?([^0|1|2|10])+/
It captures the negative sign, but it still does it when the number is -2 or -1, which I don't want. Also, it doesn't capture 11.
How should I change the expression to match the numbers I want to find. Additionally, is there a better way to find those numbers in a string?

A:

How should I change the expression to match the numbers I want to find. Additionally, is there a better way to find those numbers in a string?

Just use simple regex that'll match all the numbers from string and then filter the numbers
// Define the exclude numbers list:
// (for maintainability in the future, should excluded numbers ever change, 
// this is the only line to update)
var excludedNos = ['-2', '-1', '0', '1', '2', '10'];

var nos = (str.match(/-?\d+/g) || []).filter(function(no) {
    return excludedNos.indexOf(no) === -1;
});

Demo

