/(.*?)\z/m =~ "a\n"
p $1
# => "a\n"

/(.*?)\Z/m =~ "a\n"
p $1
# => "a"