The Ruby %r{ } expression

前端 未结 5 1140
暗喜
暗喜 2020-12-04 09:21

In a model there is a field

validates :image_file_name, :format => { :with => %r{\\.(gif|jpg|jpeg|png)$}i

It looks pretty odd for me.

5条回答
  •  天命终不由人
    2020-12-04 09:52

    \. => contains a dot
    (gif|jpg|jpeg|png) => then, either one of these extensions
    $ => the end, nothing after it
    i => case insensitive

    And it's the same as writing /\.(gif|jpg|jpeg|png)$/i.

提交回复
热议问题