Could someone tell me what the \.
and i
on the :with
-line in the following are used for?
validates :image_url, allow_blank: true, format: {
with: %r{\.(gif|jpg|png)\Z}i,
message: 'must be a URL for GIF, JPG or PNG file.'
}
%r{}
is used for regular expressions.
\.
is looking for the literal character .
. You need the \
to escape because just using .
means something else entirely (any character matches).
i
is used for case insensitive searches.
Essentially, your regex is matching for anything that ends in .gif
, .jpg
or .png
. These could also be something like .GiF
because of the case insensitive search.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With