What's a regex that matches all numbers except 1, 2 and 25?

Not that a regex is the best tool for this, but if you insist...

Use a negative lookahead:

/^(?!(?:1|2|25)$)\d+/

See it here in action: http://regexr.com/39df2


You could use a pattern like this:

^([03-9]\d*|1\d+|2[0-46-9]\d*|25\d+)$

Or if your regex engine supports it, you could just use a negative lookahead assertion ((?!…)) like this:

^(?!1$|25?$)\d+$

However, you'd probably be better off simply parsing the number in code and ensuring that it doesn't equal one of the prohibited values.