The regexp ^a*$ says that there may be zero or more a characters followed by an optional newline and then the end of the string. When $foo is '1' then the end of the string is tested before matching the '1'. Your pattern succeeded when you omitted $ because you didn't require that the you'd gotten to the end of the string. '1' =~ /^a*/ succeeds with no characters matched like /^/ while 'a' =~ /^a*$/ succeeds with all three parts matched: /^a*$/.
⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊
In reply to Re: Regex Semantics
by diotalevi
in thread Regex Semantics
by cbro
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |