The Ruby %r{ } expression

前端 未结 5 1148
暗喜
暗喜 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条回答
  •  旧时难觅i
    2020-12-04 09:38

    With %r, you could use any delimiters.

    You could use %r{} or %r[] or %r!! etc.

    The benefit of using other delimeters is that you don't need to escape the / used in normal regex literal.

提交回复
热议问题