Regular expressions with validations in RoR 4

^ and $ are Start of Line and End of Line anchors. While \A and \z are Permanent Start of String and End of String anchors.
See the difference:

string = "abcde\nzzzz"
# => "abcde\nzzzz"

/^abcde$/ === string
# => true

/\Aabcde\z/ === string
# => false

So Rails is telling you, “Are you sure you want to use ^ and $? Don’t you want to use \A and \z instead?”

There is more on the rails security concern that generates this warning here.

Leave a Comment