Why not \Z, you ask? \Z will match to the end of the string but ignore a trailing newline.
irb(main):001:0> !!("hello\n" =~ /\Ahello\z/) => false irb(main):002:0> !!("hello\n" =~ /\Ahello\Z/) => true
Why not \Z, you ask? \Z will match to the end of the string but ignore a trailing newline.