To say that using "\z" is "the correct regex solution" (and imply that using "$" is "incorrect") is a bit silly, esp. in the absence of more detailed info regarding the application.
If, as the OP requested, the variable must contain an integer between 1 and 5 inclusive, "1\n" seems like an invalid option. Unfortunately, /^\d$/ gives a false positive for that value.
But in many common situations, they behave the same...
I can only think of one case, and that's where the string does not have a trailing newline.
In reply to Re^4: Quicker way to do this IF statement 1-5
by chromatic
in thread Quicker way to do this IF statement 1-5
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |