If you want one or two digits at the end, put $
at the end of the regular expression. Also, in JavaScript, regular expression literals are written with /.../
, not "..."
:
var re = /(\d{1,2})$/;
// $ here -----------^
There, the /
at either end is not part of the expression, it marks the start and end of the expression (like "
and '
do for strings).
$
is called an "anchor" and it means "the end of the input." (There's another one, ^
, which means "the beginning of the input.")